// Public members

        public static void CopyTo(this IHttpWebRequestOptions options, IHttpWebRequest httpWebRequest, bool copyIfNull = true)
        {
            if (copyIfNull || !string.IsNullOrEmpty(options.Accept))
            {
                httpWebRequest.Accept = options.Accept;
            }

            if (copyIfNull || !string.IsNullOrEmpty(options.AcceptLanguage))
            {
                httpWebRequest.Headers[HttpRequestHeader.AcceptLanguage] = options.AcceptLanguage;
            }

            httpWebRequest.AutomaticDecompression = options.AutomaticDecompression;

            if (copyIfNull || !(options.Cookies is null))
            {
                httpWebRequest.CookieContainer = options.Cookies;
            }

            if (copyIfNull || !(options.Credentials is null))
            {
                httpWebRequest.Credentials = options.Credentials;
            }

            if (copyIfNull || !(options.Proxy is null))
            {
                httpWebRequest.Proxy = options.Proxy;
            }

            if (copyIfNull || !string.IsNullOrEmpty(options.UserAgent))
            {
                httpWebRequest.UserAgent = options.UserAgent;
            }
        }
        public static void CopyTo(this IHttpWebRequestOptions options, HttpWebRequestOptions other, bool copyIfNull = true)
        {
            if (copyIfNull || !string.IsNullOrEmpty(options.Accept))
            {
                other.Accept = options.Accept;
            }

            if (copyIfNull || !string.IsNullOrEmpty(options.AcceptLanguage))
            {
                other.AcceptLanguage = options.AcceptLanguage;
            }

            other.AutomaticDecompression = options.AutomaticDecompression;

            if (copyIfNull || !(options.Cookies is null))
            {
                other.Cookies = options.Cookies;
            }

            if (copyIfNull || !(options.Credentials is null))
            {
                other.Credentials = options.Credentials;
            }

            if (copyIfNull || !(options.Proxy is null))
            {
                other.Proxy = options.Proxy;
            }

            if (copyIfNull || !string.IsNullOrEmpty(options.UserAgent))
            {
                other.UserAgent = options.UserAgent;
            }
        }
        public static HttpWebRequestOptions Combine(IHttpWebRequestOptions options1, IHttpWebRequestOptions options2, bool copyIfNull = true)
        {
            HttpWebRequestOptions result = new HttpWebRequestOptions(options1);

            result.Combine(options2, copyIfNull);

            return(result);
        }
Example #4
0
        protected HttpWebRequestFactoryBase(IHttpWebRequestOptions options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.options = options;
        }
        public HttpWebRequestOptionsFactory(IHttpWebRequestOptions webRequestOptions)
        {
            if (webRequestOptions is null)
            {
                throw new ArgumentNullException(nameof(webRequestOptions));
            }

            this.defaultWebRequestOptions = webRequestOptions;
        }
 public static void CopyTo(this IHttpWebRequestOptions options, WebClient webClient)
 {
     webClient.Headers[HttpRequestHeader.Accept]         = options.Accept;
     webClient.Headers[HttpRequestHeader.AcceptLanguage] = options.AcceptLanguage;
     //webClient.AutomaticDecompression = options.AutomaticDecompression;
     //webClient.CookieContainer = options.Cookies;
     webClient.Credentials = options.Credentials;
     webClient.Proxy       = options.Proxy;
     webClient.Headers[HttpRequestHeader.UserAgent] = options.UserAgent;
 }
Example #7
0
 public CurlHttpWebRequestFactory(IHttpWebRequestOptions options)
 {
     if (File.Exists(LibCurl.LibCurlPath) || !File.Exists(LibCurl.CurlExecutablePath))
     {
         webRequestFactory = new LibCurlHttpWebRequestFactory(options);
     }
     else
     {
         webRequestFactory = new BinCurlHttpWebRequestFactory(options);
     }
 }
        public static IWebClient WithOptions(this IWebClient client, IHttpWebRequestOptions options)
        {
            client.Headers[HttpRequestHeader.Accept]         = options.Accept;
            client.Headers[HttpRequestHeader.AcceptLanguage] = options.AcceptLanguage;
            //webClient.AutomaticDecompression = options.AutomaticDecompression;
            //webClient.CookieContainer = options.Cookies;
            client.Credentials = options.Credentials;
            client.Proxy       = options.Proxy;
            client.Headers[HttpRequestHeader.UserAgent] = options.UserAgent;

            return(client);
        }
        // Private members

        private void Combine(IHttpWebRequestOptions other, bool copyIfNull = true)
        {
            if (copyIfNull || !string.IsNullOrWhiteSpace(other.Accept))
            {
                Accept = other.Accept;
            }

            if (copyIfNull || !string.IsNullOrWhiteSpace(other.AcceptLanguage))
            {
                AcceptLanguage = other.AcceptLanguage;
            }

            if (copyIfNull || other.AllowAutoRedirect.HasValue)
            {
                AllowAutoRedirect = other.AllowAutoRedirect;
            }

            if (copyIfNull || other.AutomaticDecompression != DecompressionMethods.None)
            {
                AutomaticDecompression = other.AutomaticDecompression;
            }

            if (copyIfNull || other.Cookies is object)
            {
                Cookies = other.Cookies;
            }

            if (copyIfNull || other.Credentials is object)
            {
                Credentials = other.Credentials;
            }

            if (Headers is null)
            {
                Headers = other.Headers.Clone();
            }
            else if (other.Headers is object)
            {
                other.Headers.CopyTo(Headers);
            }

            if (copyIfNull || other.Proxy is object)
            {
                Proxy = other.Proxy;
            }

            if (copyIfNull || !string.IsNullOrWhiteSpace(other.UserAgent))
            {
                UserAgent = other.UserAgent;
            }
        }
Example #10
0
        public void SetOptions(string domain, IHttpWebRequestOptions options)
        {
            lock (uriOptionsMutex) {
                IHttpWebRequestOptions uriOptions = FindOptionsByUri(domain);

                if (!(uriOptions is null))
                {
                    this.uriOptions.RemoveAll(item => item.Options == uriOptions);
                }

                // Allow the user to just clear the existing options if a null argument is given.

                if (!(options is null))
                {
                    this.uriOptions.Add(new UriOptions(domain, options));
                }
            }
        }
 public BinCurlHttpWebRequestFactory(IHttpWebRequestOptions options) :
     this(new HttpWebRequestOptionsFactory(options))
 {
 }
Example #12
0
        public static HttpWebRequest WithOptions(this HttpWebRequest httpWebRequest, IHttpWebRequestOptions options, bool copyIfNull = true)
        {
            WithOptions(new HttpWebRequestAdapter(httpWebRequest), options, copyIfNull);

            return(httpWebRequest);
        }
Example #13
0
        public static IHttpWebRequest WithOptions(this IHttpWebRequest httpWebRequest, IHttpWebRequestOptions options, bool copyIfNull = true)
        {
            if (copyIfNull || !string.IsNullOrWhiteSpace(options.Accept))
            {
                httpWebRequest.Accept = options.Accept;
            }

            if (copyIfNull || !string.IsNullOrWhiteSpace(options.AcceptLanguage))
            {
                httpWebRequest.Headers[HttpRequestHeader.AcceptLanguage] = options.AcceptLanguage;
            }

            if (copyIfNull || options.AllowAutoRedirect.HasValue)
            {
                httpWebRequest.AllowAutoRedirect = options.AllowAutoRedirect ?? httpWebRequest.AllowAutoRedirect;
            }

            httpWebRequest.AutomaticDecompression = options.AutomaticDecompression;

            if (copyIfNull || options.Cookies is object)
            {
                httpWebRequest.CookieContainer = options.Cookies;
            }

            if (copyIfNull || options.Credentials is object)
            {
                httpWebRequest.Credentials = options.Credentials;
            }

            if (httpWebRequest.Headers is object && options.Headers is object)
            {
                httpWebRequest.WithHeaders(options.Headers);
            }

            if (copyIfNull || options.Proxy is object)
            {
                httpWebRequest.Proxy = options.Proxy;
            }

            if (copyIfNull || !string.IsNullOrWhiteSpace(options.UserAgent))
            {
                httpWebRequest.UserAgent = options.UserAgent;
            }

            return(httpWebRequest);
        }
 public OptionsInfo(IHttpWebRequestOptions webRequestOptions, bool copyIfNull)
 {
     WebRequestOptions = webRequestOptions;
     CopyIfNull        = copyIfNull;
 }
 public void Add(Uri endpoint, IHttpWebRequestOptions options, bool copyIfNull = true)
 {
     lock (webRequestOptions)
         webRequestOptions[endpoint] = new OptionsInfo(options, copyIfNull);
 }
 public BinCurlHttpWebRequestFactory(IHttpWebRequestOptions options, string curlExecutablePath) :
     this(options) {
     this.curlExecutablePath = curlExecutablePath;
 }
Example #17
0
 public UriOptions(string domain, IHttpWebRequestOptions options)
 {
     this.Domain  = domain;
     this.Options = options;
 }
Example #18
0
 public void SetOptions(IHttpWebRequestOptions options)
 {
     this.options = options;
 }
Example #19
0
 public void SetOptions(string domain, IHttpWebRequestOptions options)
 {
     webRequestFactory.SetOptions(domain, options);
 }
Example #20
0
 public void SetOptions(IHttpWebRequestOptions options)
 {
     webRequestFactory.SetOptions(options);
 }
        public static WebClient WithOptions(this WebClient client, IHttpWebRequestOptions options)
        {
            WithOptions(new WebClientAdapter(client), options);

            return(client);
        }
 public BinCurlHttpWebRequestFactory(IHttpWebRequestOptions options, ICurlWebRequestOptions curlOptions) :
     this(new HttpWebRequestOptionsFactory(options), curlOptions)
 {
 }
Example #23
0
 public HttpWebRequestOptions(IHttpWebRequestOptions other, bool copyIfNull = true)
 {
     other.CopyTo(this, copyIfNull);
 }
Example #24
0
 public LibCurlHttpWebRequestFactory(IHttpWebRequestOptions options) :
     base(options)
 {
 }
 public HttpWebRequestOptions(IHttpWebRequestOptions other, bool copyIfNull = true)
 {
     Combine(other, copyIfNull);
 }