Skip to content

Commit 68b8be9

Browse files
committed
add missing file
1 parent f06f71b commit 68b8be9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.IO;
2+
using System.Net.Http;
3+
using System.Text;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
internal sealed class ResponseCaptureHandler : DelegatingHandler
8+
{
9+
private readonly string _path;
10+
11+
public ResponseCaptureHandler(string path) : base(new HttpClientHandler())
12+
{
13+
_path = path;
14+
}
15+
16+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
17+
{
18+
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
19+
try
20+
{
21+
var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
22+
await File.WriteAllTextAsync(_path, body, cancellationToken).ConfigureAwait(false);
23+
response.Content = new StringContent(body, Encoding.UTF8, response.Content.Headers?.ContentType?.MediaType ?? "application/json");
24+
}
25+
catch
26+
{
27+
}
28+
29+
return response;
30+
}
31+
}

0 commit comments

Comments
 (0)