@@ -28,11 +28,11 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null, IReques
2828 {
2929 var defaultHandlersEnumerable = CreateDefaultHandlers ( optionsForHandlers ) ;
3030 int count = 0 ;
31- foreach ( var _ in defaultHandlersEnumerable ) count ++ ;
31+ foreach ( var _ in defaultHandlersEnumerable ) count ++ ;
3232
3333 var defaultHandlersArray = new DelegatingHandler [ count ] ;
3434 int index = 0 ;
35- foreach ( var handler2 in defaultHandlersEnumerable )
35+ foreach ( var handler2 in defaultHandlersEnumerable )
3636 {
3737 defaultHandlersArray [ index ++ ] = handler2 ;
3838 }
@@ -48,11 +48,11 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null, IReques
4848 /// <returns>The <see cref="HttpClient"/> with the custom handlers.</returns>
4949 public static HttpClient Create ( IList < DelegatingHandler > handlers , HttpMessageHandler ? finalHandler = null )
5050 {
51- if ( handlers == null || handlers . Count == 0 )
51+ if ( handlers == null || handlers . Count == 0 )
5252 return Create ( finalHandler ) ;
5353
5454 DelegatingHandler [ ] handlersArray = new DelegatingHandler [ handlers . Count ] ;
55- for ( int i = 0 ; i < handlers . Count ; i ++ )
55+ for ( int i = 0 ; i < handlers . Count ; i ++ )
5656 {
5757 handlersArray [ i ] = handlers [ i ] ;
5858 }
@@ -91,21 +91,21 @@ public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? o
9191 HeadersInspectionHandlerOption ? headersInspectionHandlerOption = null ;
9292 BodyInspectionHandlerOption ? bodyInspectionHandlerOption = null ;
9393
94- foreach ( var option in optionsForHandlers )
94+ foreach ( var option in optionsForHandlers )
9595 {
96- if ( uriReplacementOption == null && option is UriReplacementHandlerOption uriOption )
96+ if ( uriReplacementOption == null && option is UriReplacementHandlerOption uriOption )
9797 uriReplacementOption = uriOption ;
98- else if ( retryHandlerOption == null && option is RetryHandlerOption retryOption )
98+ else if ( retryHandlerOption == null && option is RetryHandlerOption retryOption )
9999 retryHandlerOption = retryOption ;
100- else if ( redirectHandlerOption == null && option is RedirectHandlerOption redirectOption )
100+ else if ( redirectHandlerOption == null && option is RedirectHandlerOption redirectOption )
101101 redirectHandlerOption = redirectOption ;
102- else if ( parametersNameDecodingOption == null && option is ParametersNameDecodingOption parametersOption )
102+ else if ( parametersNameDecodingOption == null && option is ParametersNameDecodingOption parametersOption )
103103 parametersNameDecodingOption = parametersOption ;
104- else if ( userAgentHandlerOption == null && option is UserAgentHandlerOption userAgentOption )
104+ else if ( userAgentHandlerOption == null && option is UserAgentHandlerOption userAgentOption )
105105 userAgentHandlerOption = userAgentOption ;
106- else if ( headersInspectionHandlerOption == null && option is HeadersInspectionHandlerOption headersInspectionOption )
106+ else if ( headersInspectionHandlerOption == null && option is HeadersInspectionHandlerOption headersInspectionOption )
107107 headersInspectionHandlerOption = headersInspectionOption ;
108- else if ( bodyInspectionHandlerOption == null && option is BodyInspectionHandlerOption bodyInspectionOption )
108+ else if ( bodyInspectionHandlerOption == null && option is BodyInspectionHandlerOption bodyInspectionOption )
109109 bodyInspectionHandlerOption = bodyInspectionOption ;
110110 }
111111
@@ -148,19 +148,19 @@ public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? o
148148 /// <returns>The created <see cref="DelegatingHandler"/>.</returns>
149149 public static DelegatingHandler ? ChainHandlersCollectionAndGetFirstLink ( HttpMessageHandler ? finalHandler , params DelegatingHandler [ ] handlers )
150150 {
151- if ( handlers == null || handlers . Length == 0 ) return default ;
151+ if ( handlers == null || handlers . Length == 0 ) return default ;
152152 var handlersCount = handlers . Length ;
153- for ( var i = 0 ; i < handlersCount ; i ++ )
153+ for ( var i = 0 ; i < handlersCount ; i ++ )
154154 {
155155 var handler = handlers [ i ] ;
156156 var previousItemIndex = i - 1 ;
157- if ( previousItemIndex >= 0 )
157+ if ( previousItemIndex >= 0 )
158158 {
159159 var previousHandler = handlers [ previousItemIndex ] ;
160160 previousHandler . InnerHandler = handler ;
161161 }
162162 }
163- if ( finalHandler != null )
163+ if ( finalHandler != null )
164164 handlers [ handlers . Length - 1 ] . InnerHandler = finalHandler ;
165165 return handlers [ 0 ] ; //first
166166 }
@@ -187,6 +187,8 @@ public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy =
187187 return new WinHttpHandler { Proxy = proxy , AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate , WindowsProxyUsePolicy = proxyPolicy , SendTimeout = System . Threading . Timeout . InfiniteTimeSpan , ReceiveDataTimeout = System . Threading . Timeout . InfiniteTimeSpan , ReceiveHeadersTimeout = System . Threading . Timeout . InfiniteTimeSpan , EnableMultipleHttp2Connections = true } ;
188188#elif NET5_0_OR_GREATER && ! BROWSER
189189 return new SocketsHttpHandler { Proxy = proxy , AllowAutoRedirect = false , EnableMultipleHttp2Connections = true , AutomaticDecompression = DecompressionMethods . All } ;
190+ #elif BROWSER
191+ return new HttpClientHandler { AllowAutoRedirect = false } ;
190192#else
191193 return new HttpClientHandler { Proxy = proxy , AllowAutoRedirect = false , AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate } ;
192194#endif
0 commit comments