Skip to content

Commit

Permalink
Test octet request stream
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinjahn committed Dec 12, 2024
1 parent 3fe5628 commit 5ed13f7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/http/httpClient/Middleware/BodyInspectionHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ public async Task BodyInspectionHandlerGetsRequestBodyStream()
Assert.Equal("request test", await request.Content.ReadAsStringAsync()); // response from option is separate from "normal" request stream
}

[Fact]
public async Task BodyInspectionHandlerGetsRequestBodyStreamWhenRequestIsOctetStream()
{
var option = new BodyInspectionHandlerOption { InspectRequestBody = true, };
using var invoker = GetMessageInvoker(new HttpResponseMessage(), option);

// When
var memoryStream = new MemoryStream();
var writer = new StreamWriter(memoryStream);
await writer.WriteAsync("request test");
await writer.FlushAsync();
memoryStream.Seek(0, SeekOrigin.Begin);

var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost")
{
Content = new StreamContent(memoryStream)
};
request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(
"application/octet-stream"
);

var response = await invoker.SendAsync(request, default);

// Then
Assert.NotNull(option.RequestBody);
Assert.Equal("request test", GetStringFromStream(option.RequestBody!));
Assert.Equal("request test", await request.Content.ReadAsStringAsync()); // response from option is separate from "normal" request stream
}

[Fact]
public async Task BodyInspectionHandlerGetsNullRequestBodyStreamWhenThereIsNoRequestBody()
{
Expand Down

0 comments on commit 5ed13f7

Please sign in to comment.