HttpClientTestHelpers.cs 886 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Threading;
  3. using System.Reflection;
  4. using System.Net.Http;
  5. namespace MonoTests.System.Net.Http
  6. {
  7. static class HttpClientTestHelpers
  8. {
  9. static bool initialized;
  10. static bool usingSocketsHandler;
  11. static object syncLock;
  12. internal static bool UsingSocketsHandler {
  13. get {
  14. LazyInitializer.EnsureInitialized (
  15. ref usingSocketsHandler, ref initialized, ref syncLock,
  16. () => typeof (HttpClient).Assembly.GetType ("System.Net.Http.SocketsHttpHandler") != null);
  17. return usingSocketsHandler;
  18. }
  19. }
  20. internal static bool IsSocketsHandler (HttpClientHandler handler) => UsingSocketsHandler;
  21. internal static HttpClient CreateHttpClientWithHttpClientHandler ()
  22. {
  23. return new HttpClient (CreateHttpClientHandler ());
  24. }
  25. internal static HttpClientHandler CreateHttpClientHandler ()
  26. {
  27. return new HttpClientHandler ();
  28. }
  29. }
  30. }