public ExtendedNettyFullAddress(NettyFullAddress address, IDictionary <string, string> extraHeaders, string cookies) { this.address = address; this.extraHeaders = extraHeaders; this.cookies = cookies; }
/// <summary> /// Upgrade the channel to WebSocket. /// </summary> private void upgrade(ExtendedNettyFullAddress address) { /* * ========================================= Note ================================================= * Operations on the channel must happen in the thread associated with the channel. * Otherwise subtle bugs can appear. * For example the method WebSocketClientHandshaker.finishHandshake can return before * the method WebSocketClientHandshaker.handshake returns leaving the channel pipeline in a mess. * ================================================================================================ */ chnl.EventLoop.Execute(() => { /* * If the eventLoop is overloaded, when this task is executed the channel can be broken * (for example because the server has closed it). * So the first thing to do is to check if the channel is healthy. */ if (chnl.Active) { /* set cookies and extra headers */ string cookies = address.Cookies; IDictionary <string, string> extraHeaders = address.ExtraHeaders; DefaultHttpHeaders customHeaders = new DefaultHttpHeaders(); if (extraHeaders != null) { foreach (KeyValuePair <string, string> entry in extraHeaders) { customHeaders.Add(new AsciiString(entry.Key), entry.Value); } } if (!string.ReferenceEquals(cookies, null) && cookies.Length > 0) { customHeaders.Set(HttpHeaderNames.Cookie, cookies); } /* build url */ NettyFullAddress remoteAddress = address.Address; string scheme = remoteAddress.Secure ? "wss" : "ws"; string host = remoteAddress.Host; string url; int port = remoteAddress.Port; if (host.Equals("::1")) { url = scheme + "://localhost:" + port + "/lightstreamer"; } else { url = scheme + "://" + host + ":" + port + "/lightstreamer"; } Uri uri = LsUtils.uri(url); string subprotocol = Constants.TLCP_VERSION + ".lightstreamer.com"; /* build pipeline */ WebSocketHandshakeHandler wsHandshakeHandler = new WebSocketHandshakeHandler(uri, subprotocol, customHeaders, this); PipelineUtils.populateWSPipelineForHandshake(chnl, wsHandshakeHandler); /* WS handshake */ futureTask = wsHandshakeHandler.handshake(chnl); } else { futureTask = Task.Factory.StartNew(() => Thread.Sleep(2)); } }); return; }