# Summary

Class: | WireMock.Http.HttpClientHelper
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Http\HttpClientHelper.cs
Covered lines: | 23
Uncovered lines: | 5
Coverable lines: | 28
Total lines: | 78
Line coverage: | 82.1%
Branch coverage: | 50%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
CreateHttpClient(...) | 3 | 2 | 66.67 | 66.67
SendAsync() | 5 | 0 | 100 | 100

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Http\HttpClientHelper.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Net;`
|  | `3` |  | `using System.Net.Http;`
|  | `4` |  | `using System.Threading.Tasks;`
|  | `5` |  | `using JetBrains.Annotations;`
|  | `6` |  | `using WireMock.HttpsCertificate;`
|  | `7` |  | `using WireMock.Validation;`
|  | `8` |  | ``
|  | `9` |  | `namespace WireMock.Http`
|  | `10` |  | `{`
|  | `11` |  | `internal static class HttpClientHelper`
|  | `12` |  | `{`
|  | `13` |  | `public static HttpClient CreateHttpClient(string clientX509Certificate2ThumbprintOrSubjectName = null)`
| 8 | `14` |  | `{`
|  | `15` |  | `#if NETSTANDARD`
|  | `16` |  | `var handler = new HttpClientHandler`
|  | `17` |  | `{`
|  | `18` |  | `CheckCertificateRevocationList = false,`
|  | `19` |  | `SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslPro`
|  | `20` |  | `ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true,`
|  | `21` |  | `AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate`
|  | `22` |  | `};`
|  | `23` |  | `#elif NET46`
|  | `24` |  | `var handler = new HttpClientHandler`
|  | `25` |  | `{`
|  | `26` |  | `ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true,`
|  | `27` |  | `AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate`
|  | `28` |  | `};`
|  | `29` |  | `ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;`
|  | `30` |  | `#else`
| 8 | `31` |  | `var handler = new WebRequestHandler`
| 8 | `32` |  | `{`
| 8 | `33` |  | `ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true,`
| 8 | `34` |  | `AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate`
| 8 | `35` |  | `};`
| 8 | `36` |  | `ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;`
|  | `37` |  | `#endif`
|  | `38` |  | ``
| 8 | `39` |  | `if (!string.IsNullOrEmpty(clientX509Certificate2ThumbprintOrSubjectName))`
| 0 | `40` |  | `{`
| 0 | `41` |  | `handler.ClientCertificateOptions = ClientCertificateOption.Manual;`
|  | `42` |  | ``
| 0 | `43` |  | `var x509Certificate2 = ClientCertificateHelper.GetCertificate(clientX509Certificate2ThumbprintOrSubjectN`
| 0 | `44` |  | `handler.ClientCertificates.Add(x509Certificate2);`
| 0 | `45` |  | `}`
|  | `46` |  | ``
|  | `47` |  | `// For proxy we shouldn't follow auto redirects`
| 8 | `48` |  | `handler.AllowAutoRedirect = false;`
|  | `49` |  | ``
|  | `50` |  | `// If UseCookies enabled, httpClient ignores Cookie header`
| 8 | `51` |  | `handler.UseCookies = false;`
|  | `52` |  | ``
| 8 | `53` |  | `var client = new HttpClient(handler);`
|  | `54` |  | `#if NET452 || NET46`
| 8 | `55` |  | `ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityPro`
|  | `56` |  | `#endif`
| 8 | `57` |  | `return client;`
| 8 | `58` |  | `}`
|  | `59` |  | ``
|  | `60` |  | `public static async Task<ResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] RequestMessage reques`
| 8 | `61` |  | `{`
| 8 | `62` |  | `Check.NotNull(client, nameof(client));`
| 8 | `63` |  | `Check.NotNull(requestMessage, nameof(requestMessage));`
|  | `64` |  | ``
| 8 | `65` |  | `var originalUri = new Uri(requestMessage.Url);`
| 8 | `66` |  | `var requiredUri = new Uri(url);`
|  | `67` |  | ``
|  | `68` |  | `// Create HttpRequestMessage`
| 8 | `69` |  | `var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, url);`
|  | `70` |  | ``
|  | `71` |  | `// Call the URL`
| 8 | `72` |  | `var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRea`
|  | `73` |  | ``
|  | `74` |  | `// Parse httpResponseMessage`
| 8 | `75` |  | `return await HttpResponseMessageHelper.Create(httpResponseMessage, requiredUri, originalUri);`
| 8 | `76` |  | `}`
|  | `77` |  | `}`
|  | `78` |  | `}`

# Methods/Properties

CreateHttpClient(System.String)
SendAsync()