Event arguments for the event of creating a WebRequest
Inheritance: System.EventArgs
コード例 #1
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);
			}
		}
コード例 #2
0
		public virtual void ConfigureRequest(object sender, WebRequestEventArgs e)
		{
			if (string.IsNullOrEmpty(CurrentOauthToken))
				return;

			SetHeader(e.Request.Headers, "Authorization", CurrentOauthToken);
		}
コード例 #3
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);
			}
		}
コード例 #4
0
		public virtual void ConfigureRequest(object sender, WebRequestEventArgs e)
		{
			if (string.IsNullOrEmpty(CurrentOauthToken))
				return;

#if NETFX_CORE
			e.Client.DefaultRequestHeaders.Add("Authorization", CurrentOauthToken);
#else
			SetHeader(e.Request.Headers, "Authorization", CurrentOauthToken);
#endif
			}
コード例 #5
0
		public override void ConfigureRequest(object sender, WebRequestEventArgs e)
		{
			if (CurrentOauthToken != null)
			{
				base.ConfigureRequest(sender, e);
				return;
			}
			if (apiKey != null)
			{
				e.Request.Headers["Has-Api-Key"] = "true";
			}
		}
コード例 #6
0
        protected void SetAuthorization(WebRequestEventArgs e)
        {
            if (string.IsNullOrEmpty(CurrentOauthToken))
                return;

            if (e.Client != null)
            {
                SetAuthorization(e.Client);
            }

            if (e.Request != null)
                SetHeader(e.Request.Headers, "Authorization", CurrentOauthTokenWithBearer);
        }
コード例 #7
0
		protected void SetAuthorization(WebRequestEventArgs e)
		{
			if (string.IsNullOrEmpty(CurrentOauthToken))
				return;

			if (e.Client != null)
			{
				SetAuthorization(e.Client);
			}

#if !NETFX_CORE
			if (e.Request != null)
				SetHeader(e.Request.Headers, "Authorization", CurrentOauthToken);
#endif
		}
コード例 #8
0
        public override void ConfigureRequest(object sender, WebRequestEventArgs e)
        {
            if (CurrentOauthToken != null)
            {
                base.ConfigureRequest(sender, e);
                return;
            }

            if (e.Credentials != null && e.Credentials.ApiKey != null)
            {
                if (e.Client != null)
                    e.Client.DefaultRequestHeaders.Add("Has-Api-Key", "true");
                if (e.Request != null)
                    e.Request.Headers["Has-Api-Key"] = "true";
            }
        }
コード例 #9
0
		public override void ConfigureRequest(object sender, WebRequestEventArgs e)
		{
			if (CurrentOauthToken != null)
			{
				base.ConfigureRequest(sender, e);
				return;
			}
			if (apiKey != null)
			{
#if NETFX_CORE
				e.Client.DefaultRequestHeaders.Add("Has-Api-Key", "true");
#else
				e.Request.Headers["Has-Api-Key"] = "true";
#endif
			}
		}
コード例 #10
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);
            }
        }
コード例 #11
0
 public virtual void ConfigureRequest(object sender, WebRequestEventArgs e)
 {
     SetAuthorization(e);
 }
コード例 #12
0
 private static void BeginRequest(object sender, WebRequestEventArgs e)
 {
     var profiler = MiniProfiler.Current;
     if (profiler != null && e.Request != null)
         _Requests.TryAdd(e.Request.RequestUri.PathAndQuery, profiler.Step("RavenDb: Query - " + e.Request.RequestUri.PathAndQuery));
 }
コード例 #13
0
ファイル: Monitor.cs プロジェクト: rfscotteb/RavenRelic
 private static void BeginRequest(object sender, WebRequestEventArgs e)
 {
     NewRelic.Api.Agent.NewRelic.IncrementCounter("RavenDB/RequestCount");
 }