1using System.Net.Http.Headers;
9internal class Connection : IConnection
11 private readonly Configuration _cfg;
12 private bool _disposed;
18 public Connection(Configuration configuration)
23 public async Task<HttpResponseMessage> DoPostAsync(
26 Dictionary<string, string> headers,
27 CancellationToken cancel =
default)
29 HttpResponseMessage response;
32 var policyResult = await _cfg.RetryConfiguration.RetryPolicy
33 .ExecuteAndCaptureAsync(async () => await _cfg.HttpClient.SendAsync(CreateHttpRequest(path, body, headers), cancel))
34 .ConfigureAwait(
false);
36 if (policyResult.Outcome == OutcomeType.Successful)
38 response = policyResult.Result;
42 throw policyResult.FinalException;
49 private HttpRequestMessage CreateHttpRequest(
string path,
Stream body, Dictionary<string, string> headers)
52 var request =
new HttpRequestMessage
54 Content =
new StreamContent(body),
55 Method = HttpMethod.Post,
56 RequestUri =
new Uri(_cfg.Endpoint, path)
59 request.Headers.Accept.Add(
new MediaTypeWithQualityHeaderValue(
"application/json"));
60 request.Headers.AcceptEncoding.Add(
new StringWithQualityHeaderValue(
"gzip"));
62 foreach (var header
in headers)
64 request.Headers.Add(header.Key, header.Value);
70 private void Dispose(
bool disposing)
72 if (_disposed)
return;
74 if (disposing && _cfg.DisposeHttpClient)
76 _cfg.HttpClient.Dispose();
77 GC.SuppressFinalize(
this);
Fauna.Types.Stream Stream