/// <summary>
 /// Constructor for the manual proxy connection
 /// </summary>
 /// <param name="tcpClient">TCP client being used</param>
 /// <param name="isSecure">Whether the connection is secure or not</param>
 /// <param name="dataStore">The data store being used</param>
 /// <param name="description">Description to add to the data store for each request</param>
 /// <param name="networkSettings">Network settings to be used for the connection</param>
 public SampleProxyConnection(TcpClient tcpClient,
                              bool isSecure,
                              ITrafficDataAccessor dataStore,
                              string description,
                              INetworkSettings networkSettings)
     : base(tcpClient, isSecure, dataStore, description)
 {
     _httpClient = new WebRequestClient();
     _httpClient.SetNetworkSettings(networkSettings);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Network settings
 /// </summary>
 /// <param name="netSettings"></param>
 public RequestSender(INetworkSettings netSettings)
 {
     _httpClient = new WebRequestClient();
     if (netSettings == null)
     {
         netSettings = new DefaultNetworkSettings();
         netSettings.CertificateValidationCallback = _certificateValidationCallback;
     }
     _httpClient.SetNetworkSettings(netSettings);
     _httpClient.ShouldHandleCookies = true;
 }
Ejemplo n.º 3
0
        private IHttpClient GetTrackingProxyHttpClient()
        {
            IHttpClient            webClient   = new WebRequestClient();
            DefaultNetworkSettings netSettings = new DefaultNetworkSettings();

            //send the referer request to the tracking proxy
            netSettings.CertificateValidationCallback = _networkSettings.CertificateValidationCallback;


            netSettings.WebProxy = new WebProxy(_parentProxy.Host, _parentProxy.Port);
            webClient.SetNetworkSettings(netSettings);
            return(webClient);
        }
Ejemplo n.º 4
0
        private static IHttpClient GetHttpClient()
        {
            SdkSettings.Instance.HttpRequestTimeout = 60;

            WebRequestClient client = new WebRequestClient();

            DefaultNetworkSettings networkSettings = new DefaultNetworkSettings();

            networkSettings.CertificateValidationCallback = new RemoteCertificateValidationCallback(CertificateValidator.ValidateRemoteCertificate);
            networkSettings.WebProxy = HttpWebRequest.GetSystemWebProxy();


            client.SetNetworkSettings(networkSettings);

            return(client);
        }
        public void Test_NetworkSettings_ProxyUsesAProxy()
        {
            MockProxy mockProxy;
            string    testRequest  = "GET http://site.com/ HTTP/1.1\r\n\r\n";
            string    testResponse = "HTTP/1.1 200 OK\r\n\r\n";

            TrafficViewerFile dataStore = new TrafficViewerFile();

            mockProxy = SetupMockProxy(testRequest, testResponse, dataStore);


            mockProxy.Start();



            ManualExploreProxy meProxy = new ManualExploreProxy("127.0.0.1", 0, null);             //use a random port

            meProxy.NetworkSettings.WebProxy = new WebProxy(mockProxy.Host, mockProxy.Port);
            meProxy.Start();

            WebRequestClient client          = new WebRequestClient();
            INetworkSettings networkSettings = new DefaultNetworkSettings();

            networkSettings.WebProxy = new WebProxy(meProxy.Host, meProxy.Port);

            client.SetNetworkSettings(networkSettings);

            HttpRequestInfo testReqInfo = new HttpRequestInfo(testRequest);

            Assert.AreEqual(0, dataStore.RequestCount);

            HttpResponseInfo respInfo = client.SendRequest(testReqInfo);


            meProxy.Stop();
            mockProxy.Stop();

            //test that the request goes through the mock proxy by checking the data store

            Assert.AreEqual(200, respInfo.Status);
            Assert.AreEqual(1, dataStore.RequestCount);
        }
Ejemplo n.º 6
0
        //[TestMethod]
        public void Test_ReverseProxy()
        {
            string testRequest   = "GET / HTTP/1.1\r\n";
            string site1Response = "HTTP/1.1 200 OK\r\n\r\nThis is site1";
            string site2Response = "HTTP/1.1 200 OK\r\n\r\nThis is site2";
            //create two mock sites each on a different port and a http client that send a request to the first but in fact gets redirected to the other
            TrafficViewerFile site1Source = new TrafficViewerFile();

            site1Source.AddRequestResponse(testRequest, site1Response);
            TrafficViewerFile site2Source = new TrafficViewerFile();

            site2Source.AddRequestResponse(testRequest, site2Response);

            TrafficStoreProxy mockSite1 = new TrafficStoreProxy(
                site1Source, null, "127.0.0.1", 0, 0);

            mockSite1.Start();

            TrafficStoreProxy mockSite2 = new TrafficStoreProxy(
                site2Source, null, "127.0.0.1", 0, 0);

            mockSite2.Start();

            HttpRequestInfo reqInfo = new HttpRequestInfo(testRequest);

            //request will be sent to site 1
            reqInfo.Host = mockSite1.Host;
            reqInfo.Port = mockSite1.Port;

            ReverseProxy revProxy = new ReverseProxy("127.0.0.1", 0, 0, null);

            revProxy.ExtraOptions[ReverseProxy.FORWARDING_HOST_OPT] = mockSite2.Host;
            revProxy.ExtraOptions[ReverseProxy.FORWARDING_PORT_OPT] = mockSite2.Port.ToString();
            revProxy.Start();

            //make an http client
            IHttpClient            client   = new WebRequestClient();
            DefaultNetworkSettings settings = new DefaultNetworkSettings();

            settings.WebProxy = new WebProxy(revProxy.Host, revProxy.Port);

            client.SetNetworkSettings(settings);

            //send the request Http and verify the target site received it

            HttpResponseInfo respInfo = client.SendRequest(reqInfo);
            string           respBody = respInfo.ResponseBody.ToString();


            Assert.IsTrue(respBody.Contains("This is site2"));

            //check over ssl

            reqInfo.IsSecure = true;
            respInfo         = client.SendRequest(reqInfo);
            respBody         = respInfo.ResponseBody.ToString();
            Assert.IsTrue(respBody.Contains("This is site2"));

            mockSite1.Stop();
            mockSite2.Stop();
            revProxy.Stop();
        }