Ejemplo n.º 1
0
        private void SearchForProxyInspector()
        {
            var targetType        = this.Target.GetType();
            var inspectorBaseType = typeof(ProxyInspector <>).MakeGenericType(targetType);

            Assembly currentAssembly  = Assembly.GetCallingAssembly(); // Flai.Unity.Editor assembly is always included
            var      searchAssemblies = this.AssembliesToSearchForProxyInspectors.Concat(currentAssembly.AsEnumerable());
            var      matchingTypes    = searchAssemblies.SelectMany(
                assembly => assembly.GetTypes().Where(type => inspectorBaseType.IsAssignableFrom(type) && typeof(IProxyInspector).IsAssignableFrom(type)));

            foreach (Type matchingType in matchingTypes)
            {
                if (!matchingType.ContainsGenericParameters && matchingType.GetConstructor(Type.EmptyTypes) != null)
                {
                    var inspector = Activator.CreateInstance(matchingType) as IProxyInspector;
                    if (inspector != null && this.AcceptProxyInspector(inspector))
                    {
                        _proxyInspector = inspector;
                        _hasSearchedForProxyInspector = true;
                        return;
                    }
                }
            }

            _hasSearchedForProxyInspector = true;
        }
Ejemplo n.º 2
0
        public static ProxyEngine New(string harPath = null, bool autoStart = true, IProxyInspector proxyInspector = null)
        {
            var port = 8088;
            var ip   = LocalIPAddress(); //the ip of the machine on which the proxy is running/listening

            return(new ProxyEngine(ip, port, autoStart, proxyInspector));
        }
Ejemplo n.º 3
0
 private ProxyEngine(IPAddress ipAddress, int port, bool autoStart = true, IProxyInspector proxyInspector = null)
 {
     _proxyInspector = proxyInspector;
     _listener = new ProxyListener(port, ipAddress, _proxyInspector);
     var uriBuilder = new UriBuilder("http", ipAddress.ToString(), port);
     Uri = uriBuilder.Uri;
     if (autoStart)
         _listener.Start();
 }
Ejemplo n.º 4
0
        private ProxyEngine(IPAddress ipAddress, int port, bool autoStart = true, IProxyInspector proxyInspector = null)
        {
            _proxyInspector = proxyInspector;
            _listener       = new ProxyListener(port, ipAddress, _proxyInspector);
            var uriBuilder = new UriBuilder("http", ipAddress.ToString(), port);

            Uri = uriBuilder.Uri;
            if (autoStart)
            {
                _listener.Start();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="port"></param>
 /// <param name="ipAddress"></param>
 public ProxyListener(Int32 port, IPAddress ipAddress, IProxyInspector proxyInspector)
 {
     _proxyInspector = proxyInspector;
     try
     {
         _localAddress = ipAddress;
         _port = port;
         _proxySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     }
     catch (Exception e)
     {
         throw new NotSupportedException("TcpListener not supported on this platform.", e);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="port"></param>
 /// <param name="ipAddress"></param>
 public ProxyListener(Int32 port, IPAddress ipAddress, IProxyInspector proxyInspector)
 {
     _proxyInspector = proxyInspector;
     try
     {
         _localAddress = ipAddress;
         _port         = port;
         _proxySocket  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     }
     catch (Exception e)
     {
         throw new NotSupportedException("TcpListener not supported on this platform.", e);
     }
 }
Ejemplo n.º 7
0
        public static ProxyRequest For(Socket clientSocket, IProxyInspector proxyInspector = null)
        {
            var request = new ProxyRequest
            {
                ClientSocket = clientSocket,
                ClientStream = new NetworkStream(clientSocket)
            };

            if (proxyInspector != null)
                proxyInspector.OnRequestReceived(request);

            request.ResolvePid();
            request.ReadPrologue();

            return request;
        }
Ejemplo n.º 8
0
        public static ProxyRequest For(Socket clientSocket, IProxyInspector proxyInspector = null)
        {
            var request = new ProxyRequest
            {
                ClientSocket = clientSocket,
                ClientStream = new NetworkStream(clientSocket)
            };

            if (proxyInspector != null)
            {
                proxyInspector.OnRequestReceived(request);
            }

            request.ResolvePid();
            request.ReadPrologue();

            return(request);
        }
Ejemplo n.º 9
0
 protected virtual bool AcceptProxyInspector(IProxyInspector inspector)
 {
     return(true);
 }
Ejemplo n.º 10
0
 public static ProxyEngine New(string harPath = null, bool autoStart = true, IProxyInspector proxyInspector = null)
 {
     var port = 8088;
     var ip = LocalIPAddress(); //the ip of the machine on which the proxy is running/listening
     return new ProxyEngine(ip, port, autoStart, proxyInspector);
 }