Skip to content

Commit

Permalink
Use constants instead of instance call for http handlers predefined v…
Browse files Browse the repository at this point in the history
…alues (dotnet#42941)
  • Loading branch information
marek-safar committed Oct 2, 2020
1 parent 22791d4 commit 9de3910
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public SslClientAuthenticationOptions SslOptions
set => throw new PlatformNotSupportedException();
}

public bool SupportsAutomaticDecompression => false;
public bool SupportsProxy => false;
public bool SupportsRedirectConfiguration => true;
public const bool SupportsAutomaticDecompression = false;
public const bool SupportsProxy = false;
public const bool SupportsRedirectConfiguration = true;

private Dictionary<string, object?>? _properties;
public IDictionary<string, object?> Properties => _properties ??= new Dictionary<string, object?>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
#if TARGET_BROWSER
using HttpHandlerType = System.Net.Http.BrowserHttpHandler;
#else
using HttpHandlerType = System.Net.Http.SocketsHttpHandler;
#endif

namespace System.Net.Http
{
public partial class HttpClientHandler : HttpMessageHandler
{
#if TARGET_BROWSER
private readonly BrowserHttpHandler _underlyingHandler;
#else
private readonly SocketsHttpHandler _underlyingHandler;
#endif
private readonly HttpHandlerType _underlyingHandler;
private readonly DiagnosticsHandler? _diagnosticsHandler;
private ClientCertificateOption _clientCertificateOptions;

private volatile bool _disposed;

public HttpClientHandler()
{
#if TARGET_BROWSER
_underlyingHandler = new BrowserHttpHandler();
#else
_underlyingHandler = new SocketsHttpHandler();
#endif
_underlyingHandler = new HttpHandlerType();
if (DiagnosticsHandler.IsGloballyEnabled())
{
_diagnosticsHandler = new DiagnosticsHandler(_underlyingHandler);
Expand All @@ -49,9 +46,9 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

public virtual bool SupportsAutomaticDecompression => _underlyingHandler.SupportsAutomaticDecompression;
public virtual bool SupportsProxy => _underlyingHandler.SupportsProxy;
public virtual bool SupportsRedirectConfiguration => _underlyingHandler.SupportsRedirectConfiguration;
public virtual bool SupportsAutomaticDecompression => HttpHandlerType.SupportsAutomaticDecompression;
public virtual bool SupportsProxy => HttpHandlerType.SupportsProxy;
public virtual bool SupportsRedirectConfiguration => HttpHandlerType.SupportsRedirectConfiguration;

[UnsupportedOSPlatform("browser")]
public bool UseCookies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ public bool EnableMultipleHttp2Connections
}
}

internal bool SupportsAutomaticDecompression => true;
internal bool SupportsProxy => true;
internal bool SupportsRedirectConfiguration => true;
internal const bool SupportsAutomaticDecompression = true;
internal const bool SupportsProxy = true;
internal const bool SupportsRedirectConfiguration = true;

/// <summary>
/// When non-null, a custom callback used to open new connections.
Expand Down

0 comments on commit 9de3910

Please sign in to comment.