public FullHttpProxyDataAdapter(TcpClient client, FullHttpProxyToken token, string description, Logger logger) : base(client, description) { _requestData = new MemoryStream(); _destHostname = token.Hostname; _destPort = token.Port; _logger = logger; _waitingForHeader = true; }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = null; if (_config.SslConfig.Enabled) { IDataAdapter client = null; INetworkLayer ssl = new SslNetworkLayer(_config.SslConfig); ssl.Negotiate(ref adapter, ref client, null, _logger, null, null, new PropertyBag("Root"), NetworkLayerBinding.Server); } if (adapter is HttpProxyDataAdapter) { HttpProxyDataAdapter proxyAdapter = (HttpProxyDataAdapter)adapter; token = new FullHttpProxyToken(proxyAdapter.Url.Host, proxyAdapter.Url.Port); token.State.Add("adapter", adapter); } else { DataAdapterToStream stm = new DataAdapterToStream(adapter); DataReader reader = new DataReader(stm); try { HttpRequestHeader header = HttpParser.ReadRequestHeader(reader, false, _logger); if (HandleProxyAuthentication(reader, stm, ref header)) { // We just have a connect if (header.IsConnect) { token = HandleConnect(header, stm); } else { token = HandleOtherRequest(header, stm, service); } } } catch (HttpStreamParserException ex) { _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidRequest, ex.Message); // TODO: Put in some decent error codes ReturnResponse(null, 400, "Bad Request", "GET", HttpVersion.Version11, stm); } catch (EndOfStreamException) { token = null; } } return token; }
private static void ConnectWithFullHttpProxyToken(Stream stm, FullHttpProxyToken token, Logger logger) { // Don't actually need to do anything just yet token.Status = NetStatusCodes.Success; }