コード例 #1
0
        public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
        {
            if (!RuntimeSettings.EnableWebDownloadMode)
            {
                return;
            }


            if (oldAddress != browserControl.Address || oldAddress == "")
            {
                oldAddress = browserControl.Address;
                Resources.Clear();
                ResponseHeaders.Clear();
                RequestHeaders.Clear();
            }

            var dict = response.ResponseHeaders.AllKeys.ToDictionary(x => x, x => response.ResponseHeaders[x]);

            ResponseHeaders.Add(new HeaderWrapper(request.Identifier, dict));

            var reqDict = request.Headers.AllKeys.ToDictionary(x => x, x => request.Headers[x]);

            RequestHeaders.Add(new HeaderWrapper(request.Identifier, reqDict));

            MemoryStreamResponseFilter filter;

            if (responseDictionary.TryGetValue(request.Identifier, out filter))
            {
                var data = filter.Data;
                Resources.Add(new RequestWrapper(request.Url, request.ResourceType, response.MimeType, data, request.Identifier));
            }
        }
コード例 #2
0
        /// <summary>
        /// Respuesta manual
        /// Se debe de llamar ANTES de empezar a escribir en el stream de respuesta
        /// </summary>
        /// <param name="Code">Código de la respuesta</param>
        /// <param name="Headers">Headers adicionales</param>
        public void WriteCustomResponse(string Code)
        {
            if (!ResponseHeaders.ContainsKey("Connection"))
            {
                ResponseHeaders.Add("Connection", "close");
            }

            Processor.WriteResponseCode(Code, ResponseHeaders);
        }
コード例 #3
0
 public override void Process(IWebResponse response)
 {
     //response.Send(Encoding.ASCII.GetBytes(TestResponse.Header));
     Status            = 200;
     StatusDescription = "OK";
     ResponseHeaders.Add("Content-Type", "text/html; charset=utf-8");
     response.Send(Encoding.ASCII.GetBytes(TestResponse.Response));
     response.CompleteResponse();
 }
コード例 #4
0
        public static void CopyHeadersFromHttpWebResponse(WebHeaderCollection webResponseHeaders, ResponseHeaders responseHeaders)
        {
            var keys = webResponseHeaders.Keys;

            for (int i = 0; i < keys.Count; ++i)
            {
                var k = keys[i];
                var v = webResponseHeaders.GetValues(i);
                responseHeaders.Add(k, v);
            }
        }
コード例 #5
0
 private void SetResponseHeaders(HttpResponseMessage response)
 {
     ResponseHeaders.Clear();
     foreach (var header in response.Headers)
     {
         foreach (var headerValue in header.Value)
         {
             ResponseHeaders.Add(new NameValue(header.Key, headerValue));
         }
     }
 }
コード例 #6
0
ファイル: OwinContext.cs プロジェクト: zr8091/OwinDog
        public void SetResponseHeader(string headerName, string headerValue)
        {
            if (ResponseHeaders.ContainsKey(headerName))
            {
                ResponseHeaders[headerName][0] = headerValue;
                return;
            }
            ResponseHeaders.Add(headerName, new string[]
			{
				headerValue
			});
        }
コード例 #7
0
ファイル: AsyncClient.cs プロジェクト: Warpten/CASC.NET
        public void Send(string queryString)
        {
            _client = new TcpClient(_host, _port)
            {
                ReceiveTimeout = 5000,
                NoDelay        = true
            };

            var headerString = new StringBuilder();

            headerString.AppendFormat("GET {0} HTTP/1.1\nHost: {1}\n", queryString, _host);

            RequestHeaders["Connection"] = "close";
            foreach (var headerName in RequestHeaders.AllKeys)
            {
                headerString.AppendFormat("{0}: {1}\n", headerName, RequestHeaders.Get(headerName));
            }

            Stream = new NonClosingStream(_client.GetStream());

            var queryHeaders = Encoding.ASCII.GetBytes(headerString.ToString() + '\n');

            Stream.Write(queryHeaders, 0, queryHeaders.Length);

            // No using statement, we don't want the stream to be disposed
            var textReader = new UnbufferedStreamReader(Stream);

            foreach (var line in
                     textReader.ReadUntil("\r\n\r\n")
                     .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                     .Where(line => !string.IsNullOrEmpty(line)))
            {
                if (line.Contains(':'))
                {
                    ResponseHeaders.Add(line);
                }
                else if (line.IndexOf("HTTP/", StringComparison.Ordinal) == 0)
                {
                    StatusCode = int.Parse(line.Substring(9, 3));
                }
            }

            if (!LogRequest)
            {
                return;
            }

            Console.WriteLine("{2}: http://{0}{1}", _host, queryString, StatusCode);
            Console.WriteLine(ResponseHeaders.ToString());
        }
コード例 #8
0
        public ExceptionResponse(System.Exception exception)
        {
            if (exception == null)
            {
                throw new System.ArgumentNullException(nameof(exception));
            }

            ResponseStatusCode = 500;
            ResponseHeaders.Add("Exception-Type", exception.GetType().ToString());
            ResponseHeaders.Add("Exception-Message", exception.Message);
            ResponseHeaders.Add("Content-Type", "application/json; charset=utf-8");
            ResponseBody = new JsonBody(new
            {
                Message    = exception.Message,
                Type       = exception.GetType(),
                StackTrace = exception.StackTrace
            });
        }
コード例 #9
0
        public void Add(DateTime startDateTimeUtc, DateTime endDateTimeUtc, bool isSuccessStatusCode, int statusCode, long headerLength, long responseLength, long requestSentTicks, long responseTicks, string responseHeaders, Exception exception)
        {
            lock (_lock) // TODO
            {
                StartDateTimes.Add(startDateTimeUtc);
                EndDateTimes.Add(endDateTimeUtc);
                IsSuccessStatusCodes.Add(isSuccessStatusCode);
                StatusCodes.Add(statusCode);
                HeaderLengths.Add(headerLength);
                ResponseLengths.Add(responseLength);
                RequestSentTicks.Add(requestSentTicks);
                ResponseTicks.Add(responseTicks);

                if (string.IsNullOrWhiteSpace(responseHeaders) == false)
                {
                    ResponseHeaders.Add(responseHeaders);
                }
                if (exception != null)
                {
                    Exceptions.Add(exception);
                }
            }
        }
コード例 #10
0
        private async Task <HttpResponseMessage> Forward()
        {
            HttpResponseMessage response;

            using (var client = new HttpClient {
                Timeout = TimeSpan.FromSeconds(10)
            }) {
                var requestMethod = ParseHttpMethod(HttpMethod);
                var message       = new HttpRequestMessage(requestMethod, Destination);

                foreach (var header in Headers)
                {
                    message.Headers.Add(header.Name, header.Value);
                }

                message.Headers.Host = new Uri(Destination).Host;

                if (requestMethod != System.Net.Http.HttpMethod.Get)
                {
                    message.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(Body));
                }

                response = await client.SendAsync(message);
            }

            ResponseHeaders.Clear();
            foreach (var header in response.Headers)
            {
                string value = string.Join(",", header.Value);
                ResponseHeaders.Add(new Header(header.Key, value));
            }

            ResponseBody = await response.Content.ReadAsStringAsync();

            return(response);
        }
コード例 #11
0
        /// <summary>
        /// Adds the given header object to Response
        /// </summary>
        /// <param name="newHeader"></param>
        public void AddHeader(HttpHeader newHeader)
        {
            if (NonUniqueResponseHeaders.ContainsKey(newHeader.Name))
            {
                NonUniqueResponseHeaders[newHeader.Name].Add(newHeader);
                return;
            }

            if (ResponseHeaders.ContainsKey(newHeader.Name))
            {
                var existing = ResponseHeaders[newHeader.Name];
                ResponseHeaders.Remove(newHeader.Name);

                NonUniqueResponseHeaders.Add(newHeader.Name,
                                             new List <HttpHeader>()
                {
                    existing, newHeader
                });
            }
            else
            {
                ResponseHeaders.Add(newHeader.Name, newHeader);
            }
        }
 public ContentActionResultWithCorsWithoutCaching(HttpRequest request, object model, string corsSettings)
     : base(request, model)
 {
     ResponseHeaders.Add(new KeyValuePair <string, string>("Access-Control-Allow-Origin", corsSettings));
     ResponseHeaders.Add(new KeyValuePair <string, string>("Cache-Control", "private, max-age=0, no-cache"));
 }
 public ContentActionResultWithoutCaching(HttpRequest request, object model) : base(request, model)
 {
     ResponseHeaders.Add(new KeyValuePair <string, string>("Cache-Control", "private, max-age=0, no-cache"));
 }
コード例 #14
0
 IResponseBuilder IMessageBuilder <IResponseBuilder> .WithHeader(string key, params string[] values)
 {
     ResponseHeaders.Add(key, values);
     return(this);
 }
 public ContentActionResultWithCors(HttpRequest request, object model, string corsSettings)
     : base(request, model)
 {
     ResponseHeaders
     .Add(new KeyValuePair <string, string>("Access-Control-Allow-Origin", corsSettings));
 }
コード例 #16
0
 /// <summary>
 /// Default response headers
 /// </summary>
 public FluentWebApplicationBootstrapConfiguration AddDefaultResponseHeader(ResponseHeaderAttribute responseHeader)
 {
     ResponseHeaders.Add(responseHeader);
     return(this);
 }
コード例 #17
0
        private void GetSetDnsRecord(bool UpdateData = false)
        {
            string HtmlContent = String.Empty;
            string apiurl      = $"https://api.godaddy.com/v1/domains/{Domain}/records/{Type.ToString()}/{Name}";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest webreq = (HttpWebRequest)System.Net.WebRequest.Create(apiurl);

            webreq.Headers.Add("Authorization", $"sso-key {Key}:{Secret}");
            webreq.ContentType = "application/json";
            webreq.Accept      = "application/json";
            webreq.UserAgent   = UserAgent;

            if (UpdateData == true && RecordToJson().Length > 0)
            {
                webreq.Method        = "PUT";
                webreq.ContentLength = RecordToJson().Length;
                using (var writer = new StreamWriter(webreq.GetRequestStream()))
                {
                    writer.Write(RecordToJson());
                }
            }
            else
            {
                webreq.Method = "GET";
            }

            try
            {
                HttpWebResponse WebResponse    = (HttpWebResponse)webreq.GetResponse();
                Stream          responseStream = responseStream = WebResponse.GetResponseStream();

                StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
                HtmlContent = Reader.ReadToEnd();

                ResponseHeaders.Clear();
                foreach (string headkey in WebResponse.Headers.AllKeys)
                {
                    ResponseHeaders.Add(headkey, WebResponse.Headers[headkey]);
                }

                if (WebResponse.StatusCode == HttpStatusCode.OK && HtmlContent.Length > 0)
                {
                    dynamic jsondata = JsonConvert.DeserializeObject(HtmlContent);

                    if (jsondata != null && jsondata.Count != null && jsondata.Count > 0 && jsondata[0] != null)
                    {
                        if (jsondata[0].data != null)
                        {
                            Data = jsondata[0].data.ToString().Trim();
                        }
                        if (jsondata[0].name != null)
                        {
                            Name = jsondata[0].name.ToString().Trim();
                        }
                        if (jsondata[0].ttl != null)
                        {
                            Ttl = jsondata[0].ttl;
                        }
                        if (jsondata[0].type != null)
                        {
                            Type = (RecordTypes)System.Enum.Parse(typeof(RecordTypes), jsondata[0].type.ToString().Trim());                                                   //jsondata[0].type.ToString().Trim();
                        }
                        StatusCode = StatusCodes.OK;
                    }
                    else
                    {
                        StatusCode = StatusCodes.EmptyResponse;
                    }
                }
                else
                {
                    StatusCode = StatusCodes.EmptyResponse;
                }

                WebResponse.Close();
                responseStream.Close();
            }
            catch (Exception e)
            {
                ExceptionMessage = e.Message;
                StatusCode       = StatusCodes.EmptyResponse;
            }
        }