diff options
author | Martin Baulig <mabaul@microsoft.com> | 2019-03-06 22:56:42 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-03-06 22:56:42 +0300 |
commit | 6034bc00c432356a31208136b871ed152eb3f8d3 (patch) | |
tree | de30596d415f97dca0ba7190c26bb6def73a9597 /mcs/class/System.Net.Http.WebRequest | |
parent | 835c8590ca89b59b09abc58f6ccb6fa17a1d3243 (diff) |
Introducing `HttpClient.CreateDefaultHandler()`. (#13305)
* The default `HttpClient` constructor now calls a static method `CreateDefaultHandler()`;
we provide a platform-specific implementation of it.
* Replaced `HeaderUtils` with `PlatformHelper` and removed the `LEGACY_HTTPCLIENT` conditional.
* Added a new `socketshandler.sources` file to keep the sources in one place.
* Use a reflection check in the tests instead of the `LEGACY_HTTPCLIENT` conditional.
* This allows us to also get rid of the `SOCKETSHTTPHANDLER` define.
Diffstat (limited to 'mcs/class/System.Net.Http.WebRequest')
-rw-r--r-- | mcs/class/System.Net.Http.WebRequest/Makefile | 5 | ||||
-rw-r--r-- | mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs | 18 |
2 files changed, 13 insertions, 10 deletions
diff --git a/mcs/class/System.Net.Http.WebRequest/Makefile b/mcs/class/System.Net.Http.WebRequest/Makefile index deca27db3fd..7c9e87b4fab 100644 --- a/mcs/class/System.Net.Http.WebRequest/Makefile +++ b/mcs/class/System.Net.Http.WebRequest/Makefile @@ -11,9 +11,4 @@ LIB_MCS_FLAGS = TEST_MCS_FLAGS = -d:WEBREQUEST_HANDLER TEST_LIB_REFS = System System.Core System.Net.Http System.Net.Http.WebRequest -ifndef SOCKETSHTTPHANDLER -TEST_MCS_FLAGS += -d:LEGACY_HTTPCLIENT -LIB_MCS_FLAGS += -d:LEGACY_HTTPCLIENT -endif - include ../../build/library.make diff --git a/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs b/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs index 47b1410bf2f..3c075ac8057 100644 --- a/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs +++ b/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Reflection; using System.Net.Http; @@ -6,11 +7,18 @@ namespace MonoTests.System.Net.Http { static class HttpClientTestHelpers { -#if LEGACY_HTTPCLIENT - internal static bool UsingSocketsHandler => false; -#else - internal static bool UsingSocketsHandler => true; -#endif + static bool initialized; + static bool usingSocketsHandler; + static object syncLock; + + internal static bool UsingSocketsHandler { + get { + LazyInitializer.EnsureInitialized ( + ref usingSocketsHandler, ref initialized, ref syncLock, + () => typeof (HttpClient).Assembly.GetType ("System.Net.Http.SocketsHttpHandler") != null); + return usingSocketsHandler; + } + } internal static bool IsSocketsHandler (HttpClientHandler handler) => false; |