private static HttpHandlerContext CalculateHandlerContext(GrpcChannelOptions channelOptions) { if (channelOptions.HttpHandler == null) { // No way to know what handler a HttpClient is using so assume custom. var type = channelOptions.HttpClient == null ? HttpHandlerType.SocketsHttpHandler : HttpHandlerType.Custom; return(new HttpHandlerContext(type)); } if (HttpRequestHelpers.HasHttpHandlerType(channelOptions.HttpHandler, "System.Net.Http.WinHttpHandler")) { return(new HttpHandlerContext(HttpHandlerType.WinHttpHandler)); } if (HttpRequestHelpers.HasHttpHandlerType(channelOptions.HttpHandler, "System.Net.Http.SocketsHttpHandler")) { HttpHandlerType type; TimeSpan? connectTimeout; #if NET5_0_OR_GREATER var socketsHttpHandler = HttpRequestHelpers.GetHttpHandlerType <SocketsHttpHandler>(channelOptions.HttpHandler) !; type = HttpHandlerType.SocketsHttpHandler; connectTimeout = socketsHttpHandler.ConnectTimeout; // Check if the SocketsHttpHandler is being shared by channels. // It has already been setup by another channel (i.e. ConnectCallback is set) then // additional channels can use advanced connectivity features. if (!BalancerHttpHandler.IsSocketsHttpHandlerSetup(socketsHttpHandler)) { // Someone has already configured the handler callback. // This channel can't support advanced connectivity features. if (socketsHttpHandler.ConnectCallback != null) { type = HttpHandlerType.Custom; connectTimeout = null; } } #else type = HttpHandlerType.SocketsHttpHandler; connectTimeout = null; #endif return(new HttpHandlerContext(type, connectTimeout)); } if (HttpRequestHelpers.GetHttpHandlerType <HttpClientHandler>(channelOptions.HttpHandler) != null) { return(new HttpHandlerContext(HttpHandlerType.HttpClientHandler)); } return(new HttpHandlerContext(HttpHandlerType.Custom)); }
private static HttpHandlerType CalculateHandlerType(GrpcChannelOptions channelOptions) { if (channelOptions.HttpHandler == null) { // No way to know what handler a HttpClient is using so assume custom. return(channelOptions.HttpClient == null ? HttpHandlerType.SocketsHttpHandler : HttpHandlerType.Custom); } return(HttpRequestHelpers.CalculateHandlerType(channelOptions.HttpHandler)); }
public BalancerHttpHandler(HttpMessageHandler innerHandler, ConnectionManager manager) : base(innerHandler) { _manager = manager; #if NET5_0_OR_GREATER var socketsHttpHandler = HttpRequestHelpers.GetHttpHandlerType <SocketsHttpHandler>(innerHandler); if (socketsHttpHandler != null) { socketsHttpHandler.ConnectCallback = OnConnect; } #endif }
public void Execute(object parameter) { this.LoginInProgress = true; // submit http request HttpRequestHelpers.PostAsync <UserAuth>(new Uri("http://127.0.0.1/email?action=send"), new UserAuth() { Foo = "Test" }, result => { this.LoginInProgress = false; }); }
public BalancerHttpHandler(HttpMessageHandler innerHandler, HttpHandlerType httpHandlerType, ConnectionManager manager) : base(innerHandler) { _manager = manager; #if NET5_0_OR_GREATER if (httpHandlerType == HttpHandlerType.SocketsHttpHandler) { var socketsHttpHandler = HttpRequestHelpers.GetHttpHandlerType <SocketsHttpHandler>(innerHandler); CompatibilityHelpers.Assert(socketsHttpHandler != null, "Should have handler with this handler type."); socketsHttpHandler.ConnectCallback = OnConnect; } #endif }
private bool Http2NotSupported() { if (Environment.Version.Major == 4 && Environment.Version.Minor == 0 && Environment.Version.Build == 30319 && InnerHandler != null && HttpRequestHelpers.HasHttpHandlerType <HttpClientHandler>(InnerHandler)) { // https://docs.microsoft.com/dotnet/api/system.environment.version#remarks // Detect runtimes between .NET 4.5 and .NET Core 2.1 // The default HttpClientHandler doesn't support HTTP/2. return(true); } return(false); }
/// <summary> /// Cria um request assíncrono na API da SPTrans /// </summary> /// <typeparam name="T">Classe T para desserialização dos dados</typeparam> /// <param name="url">Url para request</param> /// <returns>Retorna um objeto T deserializado</returns> public async Task <T> CreateGetRequestAsync <T>(string url) { using (var httpClient = new HttpClient()) { var cookie = _context.HttpContext.User.Claims .Where(c => c.Type == "SPTransCookie").FirstOrDefault(); var message = HttpRequestHelpers.CreateMessage(string.Concat(_configuration.SPTransBaseUrl, url), cookie.Value); var response = await httpClient .SendAsync(message) .ConfigureAwait(false); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException("Unauthorized"); } return(await HttpRequestHelpers.Deserialize <T>(response)); } }