Пример #1
0
        private HttpProxyToken HandleConnect(string host, string[] headers, DataAdapterToStream stm)
        {
            string hostName = null;
            int port = 80;
            string[] connectHeader = host.Split(':');
            HttpProxyToken ret = null;

            if (connectHeader.Length > 0)
            {
                hostName = connectHeader[0];
                if (connectHeader.Length > 1)
                {
                    if (!int.TryParse(connectHeader[1], out port))
                    {
                        _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidConnect, connectHeader[1]);
                        port = 0;
                    }
                }

                if (port > 0)
                {
                    UriBuilder builder = new UriBuilder(GetProbableProtocol(port), hostName);
                    builder.Port = port;

                    ret = new HttpProxyToken(hostName, port, true, headers, builder.Uri, stm);
                }
                else
                {
                    // TODO: Put in some decent error codes
                    ReturnResponse(500, "Server Error", stm);
                }
            }

            return ret;
        }
Пример #2
0
        private static void ConnectWithHttpProxyToken(Stream stm, HttpProxyToken token, Logger logger)
        {
            token.IsHTTPProxyClient = true;

            if (token.Connect)
            {
                // Send original CONNECT headers
                StringBuilder builder = new StringBuilder();
                foreach (var s in token.Headers)
                {
                    builder.Append(s);
                }

                byte[] data = GeneralUtils.MakeByteArray(builder.ToString());

                stm.Write(data, 0, data.Length);

                builder.Clear();

                // Read out response headers
                while (true)
                {
                    string nextLine = GeneralUtils.ReadLine(stm);

                    builder.Append(nextLine);

                    if (nextLine.Trim().Length == 0)
                    {
                        break;
                    }
                }

                // Smuggle data back to server
                token.Response = GeneralUtils.MakeByteArray(builder.ToString());
            }

            token.Status = NetStatusCodes.Success;
        }