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));
            }
        }
Ejemplo n.º 2
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));
         }
     }
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
            }
        }