Beispiel #1
0
        /// <summary>
        ///     Gets the connection cache key.
        /// </summary>
        /// <param name="args">The session event arguments.</param>
        /// <param name="applicationProtocol"></param>
        /// <returns></returns>
        internal async Task <string> GetConnectionCacheKey(ProxyServer server, SessionEventArgsBase args,
                                                           SslApplicationProtocol applicationProtocol)
        {
            List <SslApplicationProtocol> applicationProtocols = null;

            if (applicationProtocol != default)
            {
                applicationProtocols = new List <SslApplicationProtocol> {
                    applicationProtocol
                };
            }

            ExternalProxy customUpStreamProxy = null;

            bool isHttps = args.IsHttps;

            if (server.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await server.GetCustomUpStreamProxyFunc(args);
            }

            args.CustomUpStreamProxyUsed = customUpStreamProxy;

            return(GetConnectionCacheKey(
                       args.WebSession.Request.RequestUri.Host,
                       args.WebSession.Request.RequestUri.Port,
                       isHttps, applicationProtocols,
                       server, args.WebSession.UpStreamEndPoint ?? server.UpStreamEndPoint,
                       customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy)));
        }
        /// <summary>
        ///     Gets the connection cache key.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="session">The session event arguments.</param>
        /// <param name="applicationProtocol">The application protocol.</param>
        /// <returns></returns>
        internal async Task <string> GetConnectionCacheKey(ProxyServer server, SessionEventArgsBase session,
                                                           SslApplicationProtocol applicationProtocol)
        {
            List <SslApplicationProtocol>?applicationProtocols = null;

            if (applicationProtocol != default)
            {
                applicationProtocols = new List <SslApplicationProtocol> {
                    applicationProtocol
                };
            }

            var customUpStreamProxy = session.CustomUpStreamProxy;

            bool isHttps = session.IsHttps;

            if (customUpStreamProxy == null && server.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await server.GetCustomUpStreamProxyFunc(session);
            }

            session.CustomUpStreamProxyUsed = customUpStreamProxy;

            var uri = session.HttpClient.Request.RequestUri;
            var upStreamEndPoint = session.HttpClient.UpStreamEndPoint ?? server.UpStreamEndPoint;
            var upStreamProxy    = customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy);

            return(GetConnectionCacheKey(uri.Host, uri.Port, isHttps, applicationProtocols, upStreamEndPoint,
                                         upStreamProxy));
        }
Beispiel #3
0
        /// <summary>
        ///     Create a server connection.
        /// </summary>
        /// <param name="server">The proxy server.</param>
        /// <param name="session">The session event arguments.</param>
        /// <param name="isConnect">Is this a CONNECT request.</param>
        /// <param name="applicationProtocols"></param>
        /// <param name="noCache">if set to <c>true</c> [no cache].</param>
        /// <param name="cancellationToken">The cancellation token for this async task.</param>
        /// <returns></returns>
        internal async Task <TcpServerConnection> GetServerConnection(ProxyServer server, SessionEventArgsBase session, bool isConnect,
                                                                      List <SslApplicationProtocol>?applicationProtocols, bool noCache, CancellationToken cancellationToken)
        {
            IExternalProxy?customUpStreamProxy = null;

            bool isHttps = session.IsHttps;

            if (server.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await server.GetCustomUpStreamProxyFunc(session);
            }

            session.CustomUpStreamProxyUsed = customUpStreamProxy;

            var uri = session.HttpClient.Request.RequestUri;

            return(await GetServerConnection(
                       uri.Host,
                       uri.Port,
                       session.HttpClient.Request.HttpVersion,
                       isHttps, applicationProtocols, isConnect,
                       server, session, session.HttpClient.UpStreamEndPoint ?? server.UpStreamEndPoint,
                       customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy),
                       noCache, cancellationToken));
        }
        /// <summary>
        ///     Create a server connection.
        /// </summary>
        /// <param name="proxyServer">The proxy server.</param>
        /// <param name="session">The session event arguments.</param>
        /// <param name="isConnect">Is this a CONNECT request.</param>
        /// <param name="applicationProtocols"></param>
        /// <param name="noCache">if set to <c>true</c> [no cache].</param>
        /// <param name="cancellationToken">The cancellation token for this async task.</param>
        /// <returns></returns>
        internal async Task <TcpServerConnection> GetServerConnection(ProxyServer proxyServer, SessionEventArgsBase session, bool isConnect,
                                                                      List <SslApplicationProtocol>?applicationProtocols, bool noCache, CancellationToken cancellationToken)
        {
            IExternalProxy?customUpStreamProxy = null;

            bool isHttps = session.IsHttps;

            if (proxyServer.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await proxyServer.GetCustomUpStreamProxyFunc(session);
            }

            session.CustomUpStreamProxyUsed = customUpStreamProxy;

            var    request = session.HttpClient.Request;
            string host;
            int    port;

            if (request.Authority.Length > 0)
            {
                var authority = request.Authority;
                int idx       = authority.IndexOf((byte)':');
                if (idx == -1)
                {
                    host = authority.GetString();
                    port = 80;
                }
                else
                {
                    host = authority.Slice(0, idx).GetString();
                    port = int.Parse(authority.Slice(idx + 1).GetString());
                }
            }
            else
            {
                var uri = request.RequestUri;
                host = uri.Host;
                port = uri.Port;
            }

            return(await GetServerConnection(
                       proxyServer, host, port,
                       session.HttpClient.Request.HttpVersion,
                       isHttps, applicationProtocols, isConnect,
                       session, session.HttpClient.UpStreamEndPoint ?? proxyServer.UpStreamEndPoint,
                       customUpStreamProxy ?? (isHttps ? proxyServer.UpStreamHttpsProxy : proxyServer.UpStreamHttpProxy),
                       noCache, cancellationToken));
        }
Beispiel #5
0
        /// <summary>
        ///     Create a server connection.
        /// </summary>
        /// <param name="args">The session event arguments.</param>
        /// <param name="isConnect">Is this a CONNECT request.</param>
        /// <param name="applicationProtocols"></param>
        /// <param name="cancellationToken">The cancellation token for this async task.</param>
        /// <returns></returns>
        internal async Task <TcpServerConnection> GetServerConnection(ProxyServer server, SessionEventArgsBase args, bool isConnect,
                                                                      List <SslApplicationProtocol> applicationProtocols, bool noCache, CancellationToken cancellationToken)
        {
            ExternalProxy customUpStreamProxy = null;

            bool isHttps = args.IsHttps;

            if (server.GetCustomUpStreamProxyFunc != null)
            {
                customUpStreamProxy = await server.GetCustomUpStreamProxyFunc(args);
            }

            args.CustomUpStreamProxyUsed = customUpStreamProxy;

            return(await GetServerConnection(
                       args.WebSession.Request.RequestUri.Host,
                       args.WebSession.Request.RequestUri.Port,
                       args.WebSession.Request.HttpVersion,
                       isHttps, applicationProtocols, isConnect,
                       server, args.WebSession.UpStreamEndPoint ?? server.UpStreamEndPoint,
                       customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy),
                       noCache, cancellationToken));
        }