public RetryHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
public RestClient(HttpMessageHandler httpClientHandler) : base(httpClientHandler) { }
public RetryPolicyDelegatingHandler(HttpMessageHandler innerHandler, int maximumAmountOfRetries) : base(innerHandler) { this.maximumAmountOfRetries = maximumAmountOfRetries; }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationApiClient" /> class. /// </summary> /// <param name="domain">Your Auth0 domain, e.g. tenant.auth0.com.</param> /// <param name="diagnostics">The diagnostics.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public AuthenticationApiClient(string domain, DiagnosticsHeader diagnostics, HttpMessageHandler handler) : this(new Uri($"https://{domain}"), diagnostics, handler) { }
/// <summary> /// Initializes a new instance of the <see cref="ManagementApiClient"/> class. /// </summary> /// <param name="token">The token.</param> /// <param name="domain">Your Auth0 domain, e.g. tenant.auth0.com.</param> /// <param name="diagnostics">The diagnostics.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public ManagementApiClient(string token, string domain, DiagnosticsHeader diagnostics, HttpMessageHandler handler) : this(token, new Uri($"https://{domain}/api/v2"), diagnostics, handler) { }
public TryReplayHttpMessageHandler(Cassette cassette, HttpMessageHandler innerHandler, CookieContainer?cookieContainer = null, IEqualityComparer <CassetteRecordRequest>?comparer = null) { _replayingHttpMessageHandler = new ReplayingHttpMessageHandler(cassette, cookieContainer, comparer); _recordingHttpMessageHandler = new RecordingHttpMessageHandler(innerHandler, cassette); }
public BrowserHandler(HttpMessageHandler next) : base(next) { }
/// <inheritdoc/> public override IHttpRoute CreateRoute(string uriTemplate, IDictionary <string, object> defaults, IDictionary <string, object> constraints, IDictionary <string, object> dataTokens, HttpMessageHandler handler) { return(new HostedHttpRoute(uriTemplate, defaults, constraints, dataTokens, handler)); }
/// <summary> /// Maps the specified OData route. When the <paramref name="defaultHandler"/> is non-<c>null</c>, it will map /// it as the handler for the route. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="routeName">The name of the route to map.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> /// <param name="model">The EDM model to use for parsing OData paths.</param> /// <param name="pathHandler">The <see cref="IODataPathHandler" /> to use for parsing the OData path.</param> /// <param name="routingConventions"> /// The OData routing conventions to use for controller and action selection. /// </param> /// <param name="defaultHandler">The default <see cref="HttpMessageHandler"/> for this route.</param> /// <returns>The added <see cref="ODataRoute"/>.</returns> public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName, string routePrefix, IEdmModel model, IODataPathHandler pathHandler, IEnumerable <IODataRoutingConvention> routingConventions, HttpMessageHandler defaultHandler) { return(configuration.MapODataServiceRoute(routeName, routePrefix, builder => builder.AddService(ServiceLifetime.Singleton, sp => model) .AddService(ServiceLifetime.Singleton, sp => pathHandler) .AddService(ServiceLifetime.Singleton, sp => routingConventions.ToList().AsEnumerable()) .AddService(ServiceLifetime.Singleton, sp => defaultHandler))); }
public ConfigurationBuilder MessageHandler(HttpMessageHandler handler) { this._messageHandler = handler; return(this); }
/// <summary> /// Maps the specified OData route and the OData route attributes. When the <paramref name="defaultHandler"/> /// is non-<c>null</c>, it will map it as the default handler for the route. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="routeName">The name of the route to map.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> /// <param name="model">The EDM model to use for parsing OData paths.</param> /// <param name="defaultHandler">The default <see cref="HttpMessageHandler"/> for this route.</param> /// <returns>The added <see cref="ODataRoute"/>.</returns> public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName, string routePrefix, IEdmModel model, HttpMessageHandler defaultHandler) { return(configuration.MapODataServiceRoute(routeName, routePrefix, builder => builder.AddService(ServiceLifetime.Singleton, sp => model) .AddService(ServiceLifetime.Singleton, sp => defaultHandler) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, configuration)))); }
/// <summary> /// Maps the specified OData route and the OData route attributes. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="routeName">The name of the route to map.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> /// <param name="configureAction">The configuring action to add the services to the root container.</param> /// <returns>The added <see cref="ODataRoute"/>.</returns> public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName, string routePrefix, Action <IContainerBuilder> configureAction) { if (configuration == null) { throw Error.ArgumentNull("configuration"); } if (routeName == null) { throw Error.ArgumentNull("routeName"); } // 1) Build and configure the root container. IServiceProvider rootContainer = configuration.CreateODataRootContainer(routeName, configureAction); // 2) Resolve the path handler and set URI resolver to it. IODataPathHandler pathHandler = rootContainer.GetRequiredService <IODataPathHandler>(); // if settings is not on local, use the global configuration settings. if (pathHandler != null && pathHandler.UrlKeyDelimiter == null) { ODataUrlKeyDelimiter urlKeyDelimiter = configuration.GetUrlKeyDelimiter(); pathHandler.UrlKeyDelimiter = urlKeyDelimiter; } // 3) Resolve some required services and create the route constraint. ODataPathRouteConstraint routeConstraint = new ODataPathRouteConstraint(routeName); // Attribute routing must initialized before configuration.EnsureInitialized is called. rootContainer.GetServices <IODataRoutingConvention>(); // 4) Resolve HTTP handler, create the OData route and register it. ODataRoute route; HttpRouteCollection routes = configuration.Routes; routePrefix = RemoveTrailingSlash(routePrefix); HttpMessageHandler messageHandler = rootContainer.GetService <HttpMessageHandler>(); if (messageHandler != null) { route = new ODataRoute( routePrefix, routeConstraint, defaults: null, constraints: null, dataTokens: null, handler: messageHandler); } else { ODataBatchHandler batchHandler = rootContainer.GetService <ODataBatchHandler>(); if (batchHandler != null) { batchHandler.ODataRouteName = routeName; string batchTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch; routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler); } route = new ODataRoute(routePrefix, routeConstraint); } routes.Add(routeName, route); return(route); }
public LoggingHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
public MockHandler(HttpMessageHandler innerHandler, bool callInProcessRequest, Action customAction) : base(innerHandler) { _customAction = customAction; _callInProcessRequest = callInProcessRequest; }
public AuthenticatedHttpClientHandler(Func <Task <string> > getToken, HttpMessageHandler innerHandler) : base(innerHandler) { _getToken = getToken; }
/// <summary> /// Initializes a new instance of the <see cref="ProgressMessageHandler"/> class. /// </summary> /// <param name="innerHandler">The inner handler to which this handler submits requests.</param> public ProgressMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
public RemoteSiteExtensionManager(string serviceUrl, ICredentials credentials = null, HttpMessageHandler handler = null) : base(serviceUrl, credentials, handler) { }
/// <summary> /// Initializes a new instance of the <see cref="ManagementApiClient"/> class. /// </summary> /// <param name="token">The token.</param> /// <param name="baseUri">The base URI.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public ManagementApiClient(string token, Uri baseUri, HttpMessageHandler handler) : this(token, baseUri, null, handler) { }
public HttpLoggingHandler(HttpMessageHandler innerHandler, bool verbose) : base(innerHandler) { _verbose = verbose; }
/// <summary> /// Initializes a new instance of the <see cref="ManagementApiClient"/> class. /// </summary> /// <param name="token">The token.</param> /// <param name="domain">Your Auth0 domain, e.g. tenant.auth0.com.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public ManagementApiClient(string token, string domain, HttpMessageHandler handler) : this(token, new Uri($"https://{domain}/api/v2"), null, handler) { }
public static void UseProxy(this IAppBuilder app, ILog logger, ProxyOptions options = null, HttpMessageHandler httpClientMessageHandler = null) { options = options ?? new ProxyOptions(); if (httpClientMessageHandler == null) { app.Use <ProxyMiddleware>(logger, options); } else { app.Use <ProxyMiddleware>(logger, options, httpClientMessageHandler); } }
/// <summary> /// Makes the API request /// </summary> /// <typeparam name="T">The type of response</typeparam> /// <param name="command">The command to call.</param> /// <param name="settings">The music client settings.</param> /// <param name="queryParams">The querystring.</param> /// <param name="rawDataHandler">The convertion handler for the data received.</param> /// <param name="requestHeaders">HTTP headers to add to the request</param> /// <param name="cancellationToken">The cancellation token to cancel operation.</param> /// <returns>A response for the API request.</returns> public async Task <Response <T> > SendRequestAsync <T>( MusicClientCommand command, IMusicClientSettings settings, List <KeyValuePair <string, string> > queryParams, Func <string, T> rawDataHandler, Dictionary <string, string> requestHeaders, CancellationToken?cancellationToken) { Uri uri = command.RawUri ?? this.UriBuilder.BuildUri(command, settings, queryParams); DebugLogger.Instance.WriteLog("Calling {0}", uri.ToString()); HttpRequestMessage request = new HttpRequestMessage(command.HttpMethod, uri); HttpMessageHandler handler = this.CreateHandler(command.FollowHttpRedirects); this.AddRequestHeaders(request, requestHeaders, settings); BuildRequestBody(command, request); using (HttpClient client = new HttpClient(handler)) { client.Timeout = TimeSpan.FromMilliseconds(MusicClient.RequestTimeout); HttpStatusCode?statusCode = null; bool? mixRadioHeaderFound = null; var activeCancellationToken = cancellationToken ?? CancellationToken.None; try { activeCancellationToken.ThrowIfCancellationRequested(); using (HttpResponseMessage response = await this._requestProxy.SendRequestAsync(client, request, activeCancellationToken).ConfigureAwait(false)) { statusCode = response.StatusCode; if (command.ExpectsMixRadioHeader) { mixRadioHeaderFound = response.Headers.Contains("X-MixRadio"); } var headers = new Dictionary <string, IEnumerable <string> >(); foreach (var header in response.Headers) { headers.Add(header.Key, header.Value.ToArray()); } //// Capture Server Time offset if we haven't already... this.DeriveServerTimeOffset(response.Headers.Date, response.Headers.Age); command.SetAdditionalResponseInfo(new ResponseInfo(response.RequestMessage.RequestUri, headers)); using (var content = response.Content) { string contentType = content.Headers.ContentType != null ? content.Headers.ContentType.MediaType : null; string responseBody = await content.ReadAsStringAsync().ConfigureAwait(false); if (!response.IsSuccessStatusCode && !IsFake404(response)) { DebugLogger.Instance.WriteException( new ApiCallFailedException(response.StatusCode), new KeyValuePair <string, string>("uri", uri.ToString()), new KeyValuePair <string, string>("errorResponseBody", responseBody), new KeyValuePair <string, string>("statusCode", statusCode.ToString()), new KeyValuePair <string, string>("mixRadioHeaderFound", mixRadioHeaderFound.HasValue ? mixRadioHeaderFound.ToString() : "unknown")); } T responseItem = rawDataHandler(responseBody); return(PrepareResponse(responseItem, statusCode, contentType, null, responseBody, command.RequestId, uri, mixRadioHeaderFound, IsFake404(response))); } } } catch (Exception ex) { if (ex is OperationCanceledException) { if (activeCancellationToken.IsCancellationRequested) { DebugLogger.Instance.WriteLog("OperationCanceledException thrown due to operation being cancelled."); return(PrepareResponse(default(T), statusCode, null, new ApiCallCancelledException(), null, command.RequestId, uri, false)); } else { DebugLogger.Instance.WriteLog("OperationCanceledException thrown without operation being cancelled."); // Because Xamarin.Android fails on limited networks by cancelling the task. return(PrepareResponse(default(T), statusCode, null, new NetworkLimitedException(), null, command.RequestId, uri, false)); } } if (mixRadioHeaderFound.HasValue && !mixRadioHeaderFound.Value) { return(PrepareResponse(default(T), statusCode, null, new NetworkLimitedException(), null, command.RequestId, uri, false)); } // This is a way to check if an SSL certificate has failed. // WebExceptionStatus.TrustFailure is not supported by PCL (http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus.aspx) var webException = ex as WebException; if (webException != null && webException.Status == WebExceptionStatus.SendFailure && !mixRadioHeaderFound.HasValue) { return(PrepareResponse(default(T), statusCode, null, new SendFailureException(), null, command.RequestId, uri, false)); } DebugLogger.Instance.WriteException( new ApiCallFailedException(statusCode), new KeyValuePair <string, string>("uri", uri.ToString()), new KeyValuePair <string, string>("statusCode", statusCode.HasValue ? statusCode.ToString() : "Timeout"), new KeyValuePair <string, string>("mixRadioHeaderFound", mixRadioHeaderFound.HasValue ? mixRadioHeaderFound.ToString() : "unknown")); return(PrepareResponse(default(T), statusCode, null, ex, null, command.RequestId, uri, mixRadioHeaderFound)); } } }
public static void AddMockHandler(HttpMessageHandler mockHandler) { MockHandlerQueue.Enqueue(mockHandler); }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationApiClient" /> class. /// </summary> /// <param name="baseUri">The base URI.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public AuthenticationApiClient(Uri baseUri, HttpMessageHandler handler) : this(baseUri, null, handler) { }
public LifetimeTrackingHttpMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationApiClient" /> class. /// </summary> /// <param name="domain">Your Auth0 domain, e.g. tenant.auth0.com.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public AuthenticationApiClient(string domain, HttpMessageHandler handler) : this(new Uri($"https://{domain}"), null, handler) { }
private HttpClient GetHttpClient(TargetUri targetUri, HttpMessageHandler handler, NetworkRequestOptions options) { var httpClient = new HttpClient(handler); if (options != null) { if (options.Timeout > TimeSpan.Zero) { httpClient.Timeout = options.Timeout; } if (options.Headers != null) { foreach (var header in options.Headers) { httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); } } // Manually add the correct headers for the type of authentication that is happening because if // we rely on the framework to correctly write the headers neither GitHub nor VSTS authentication // works reliably. if (options.Authorization != null) { switch (options.Authorization) { case Token token: { // Different types of tokens are packed differently. switch (token.Type) { case TokenType.AzureAccess: { // ADAL access tokens are packed into the Authorization header. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Value); } break; case TokenType.AzureFederated: { // Federated authentication tokens are sent as cookie(s). httpClient.DefaultRequestHeaders.Add("Cookie", token.Value); } break; default: Trace.WriteLine("! unsupported token type, not appending an authentication header to the request."); break; } } break; case Credential credentials: { // Credentials are packed into the 'Authorization' header as a base64 encoded pair. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials.ToBase64String()); } break; } } } // Ensure that the user-agent string is set. if (httpClient.DefaultRequestHeaders.UserAgent is null || httpClient.DefaultRequestHeaders.UserAgent.Count == 0) { httpClient.DefaultRequestHeaders.Add("User-Agent", Global.UserAgent); } return(httpClient); }
public RestClient(HttpMessageHandler httpClientHandler, bool disposeHandler) : base(httpClientHandler, disposeHandler) { }
public Throw(HttpMessageHandler inner) : base(inner) { }
public MockHandler(HttpMessageHandler innerHandler) : this(innerHandler, true, null) { }
/// <summary> /// Starts a new session on the Deezer API. /// Setup internal workings of E.Deezer /// </summary> public static Deezer CreateNew(HttpMessageHandler httpMessageHandler = null) => new Deezer(new DeezerSession(), httpMessageHandler);
public MockHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
/// <summary> /// Initializes a new instance of the <see cref="ManagementApiClient"/> class. /// </summary> /// <param name="token">The token.</param> /// <param name="baseUri">The base URI.</param> /// <param name="diagnostics">The diagnostics.</param> /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param> public ManagementApiClient(string token, Uri baseUri, DiagnosticsHeader diagnostics, HttpMessageHandler handler) : this(token, baseUri, diagnostics, new ApiConnection(token, baseUri.AbsoluteUri, diagnostics ?? DiagnosticsHeader.Default, handler)) { }
public MockDelegatingHandler(HttpMessageHandler innerHandler, bool throwInSendAsync = false) : base(innerHandler) { _throwInSendAsync = throwInSendAsync; }
public UpdateContentLengthHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }