ConfigureRequest() public method

public ConfigureRequest ( object sender, WebRequestEventArgs e ) : void
sender object
e Raven.Abstractions.Connection.WebRequestEventArgs
return void
Exemplo n.º 1
0
		public void ConfigureRequest(RavenConnectionStringOptions options, WebRequest request)
		{
			if (RequestTimeoutInMs.HasValue)
				request.Timeout = RequestTimeoutInMs.Value;

			if (options.ApiKey == null)
			{
				request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials;
				return;
			}

			var webRequestEventArgs = new WebRequestEventArgs { Request = request };

			AbstractAuthenticator existingAuthenticator;
			if (authenticators.TryGetValue(GetCacheKey(options), out existingAuthenticator))
			{
				existingAuthenticator.ConfigureRequest(this, webRequestEventArgs);
			}
			else
			{
				var basicAuthenticator = new BasicAuthenticator(options.ApiKey, enableBasicAuthenticationOverUnsecuredHttp: false);
				var securedAuthenticator = new SecuredAuthenticator(options.ApiKey);

				basicAuthenticator.ConfigureRequest(this, webRequestEventArgs);
				securedAuthenticator.ConfigureRequest(this, webRequestEventArgs);
			}
		}
Exemplo n.º 2
0
		public void ConfigureRequest(RavenConnectionStringOptions options, HttpWebRequest request)
		{
			if (RequestTimeoutInMs.HasValue)
				request.Timeout = RequestTimeoutInMs.Value;

			if (AllowWriteStreamBuffering.HasValue)
			{
				request.AllowWriteStreamBuffering = AllowWriteStreamBuffering.Value;
				if(AllowWriteStreamBuffering.Value == false)
					request.SendChunked = true;
			}

			if (options.ApiKey == null)
			{
				request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials;
				return;
			}

			var webRequestEventArgs = new WebRequestEventArgs { Request = request, Credentials = new OperationCredentials(options.ApiKey, options.Credentials)};

			AbstractAuthenticator existingAuthenticator;
			if (authenticators.TryGetValue(GetCacheKey(options), out existingAuthenticator))
			{
				existingAuthenticator.ConfigureRequest(this, webRequestEventArgs);
			}
			else
			{
				var basicAuthenticator = new BasicAuthenticator(enableBasicAuthenticationOverUnsecuredHttp: false);
				var securedAuthenticator = new SecuredAuthenticator();

				basicAuthenticator.ConfigureRequest(this, webRequestEventArgs);
				securedAuthenticator.ConfigureRequest(this, webRequestEventArgs);
			}
		}
Exemplo n.º 3
0
        public void ConfigureRequest(RavenConnectionStringOptions options, HttpWebRequest request)
        {
            if (RequestTimeoutInMs.HasValue)
                request.Timeout = RequestTimeoutInMs.Value;

            if (options.ApiKey == null)
            {
                ICredentials credentialsToUse = CredentialCache.DefaultNetworkCredentials;
                if (options.Credentials != null)
                {
                    var networkCredentials = options.Credentials as NetworkCredential;
                    if (networkCredentials != null && options.AuthenticationScheme != null)
                    {
                        var credentialCache = new CredentialCache();
                        var uri = new Uri(options.Url);
                        credentialCache.Add(new Uri(string.Format("{0}://{1}:{2}/", uri.Scheme, uri.Host, uri.Port)), options.AuthenticationScheme, networkCredentials);

                        credentialsToUse = credentialCache;
                    }
                    else
                    {
                        credentialsToUse = options.Credentials;
                    }
                }

                request.Credentials = credentialsToUse;
                return;
            }

            var webRequestEventArgs = new WebRequestEventArgs { Request = request, Credentials = new OperationCredentials(options.ApiKey, options.Credentials)};

            AbstractAuthenticator existingAuthenticator;
            if (authenticators.TryGetValue(GetCacheKey(options), out existingAuthenticator))
            {
                existingAuthenticator.ConfigureRequest(this, webRequestEventArgs);
            }
            else
            {
                var basicAuthenticator = new BasicAuthenticator(enableBasicAuthenticationOverUnsecuredHttp: false);
                var securedAuthenticator = new SecuredAuthenticator();

                basicAuthenticator.ConfigureRequest(this, webRequestEventArgs);
                securedAuthenticator.ConfigureRequest(this, webRequestEventArgs);
            }
        }