コード例 #1
0
        protected virtual void WriteHeader(Stream target, ProxyHeader header, uint offset = 0)
        {
            target.Seek(offset, SeekOrigin.Begin);

            byte[] rawHeader = MiscUtilities.StructToBytes(header);
            target.Write(rawHeader, 0, rawHeader.Length);
        }
コード例 #2
0
        public async Task GetAsync_WithHeaders_Successful()
        {
            var headers = new List <ProxyHeader>
            {
                ProxyHeader.Create("HeaderName1", "HeaderValue1"),
                ProxyHeader.Create("HeaderName2", "HeaderValue2")
            };

            var response = await _httpProxyClient.GetAsync("http://www.example.com/", headers : headers);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
        }
コード例 #3
0
        public void Delete_WithHeaders_Successful()
        {
            var headers = new List <ProxyHeader>
            {
                ProxyHeader.Create("HeaderName1", "HeaderValue1"),
                ProxyHeader.Create("HeaderName2", "HeaderValue2")
            };

            var response = _httpProxyClient.Delete("http://www.example.com/customers/123", headers: headers);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
        }
コード例 #4
0
        public void Put_WithHeaders_Successful()
        {
            var headers = new List <ProxyHeader>
            {
                ProxyHeader.Create("HeaderName1", "HeaderValue1"),
                ProxyHeader.Create("HeaderName2", "HeaderValue2")
            };

            var response = _socks5ProxyClient.Put("http://www.example.com/", "testContent", headers: headers);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
        }
コード例 #5
0
        /// <summary>
        /// Parses the raw response into a proxy response object.
        /// </summary>
        /// <param name="response">Raw response returned by the destionation server.</param>
        /// <param name="destinationUri">Destination URI object.</param>
        /// <returns>Proxy Response</returns>
        public static ProxyResponse BuildProxyResponse(string response, Uri destinationUri)
        {
            var splitResponse = response.Split(new[] { RequestConstants.CONTENT_SEPERATOR }, 2, StringSplitOptions.None);

            if (splitResponse.Length == 1)
            {
                var status = ParseStatusCode(splitResponse[0]);

                return(ProxyResponse.Create(status, Enumerable.Empty <ProxyHeader>(), Enumerable.Empty <Cookie>(), splitResponse[0]));
            }
            else
            {
                var responseHeadersHtml = splitResponse[0];
                var statusWithHeaders   = responseHeadersHtml.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                var statusHtml = statusWithHeaders[0];
                var status     = ParseStatusCode(statusHtml);

                var headerList      = new List <ProxyHeader>();
                var cookieContainer = new CookieContainer();

                var headerArray = statusWithHeaders.Skip(1);

                foreach (var header in headerArray)
                {
                    var headerPair = header.Split(new[] { ": " }, 2, StringSplitOptions.None);

                    if (headerPair[0].ToLower().Contains(RequestConstants.SET_COOKIE_HEADER))
                    {
                        cookieContainer.SetCookies(destinationUri, headerPair[1]);
                        continue;
                    }

                    headerList.Add(ProxyHeader.Create(headerPair[0], headerPair[1]));
                }

                return(ProxyResponse.Create(status, headerList, cookieContainer.GetCookies(destinationUri), splitResponse[1]));
            }
        }