Skip to content

Commit

Permalink
Add a test for manually setting HttpWebRequest.ContentLength while bu…
Browse files Browse the repository at this point in the history
…ffering the request body (dotnet#102989)
  • Loading branch information
MihaZupan authored Jun 6, 2024
1 parent ddd19a7 commit 035ce10
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,9 +2118,11 @@ await server.AcceptConnectionAsync(_ =>
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task SendHttpPostRequest_WhenBufferingChanges_Success(bool buffering)
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, true)]
[InlineData(false, false)]
public async Task SendHttpPostRequest_WhenBufferingChanges_Success(bool buffering, bool setContentLength)
{
byte[] randomData = Encoding.ASCII.GetBytes("Hello World!!!!\n");
await LoopbackServer.CreateClientAndServerAsync(
Expand All @@ -2130,6 +2132,12 @@ await LoopbackServer.CreateClientAndServerAsync(
HttpWebRequest request = WebRequest.CreateHttp(uri);
request.Method = "POST";
request.AllowWriteStreamBuffering = buffering;

if (setContentLength)
{
request.Headers.Add("content-length", size.ToString());
}

using var stream = await request.GetRequestStreamAsync();
for (int i = 0; i < size / randomData.Length; i++)
{
Expand Down

0 comments on commit 035ce10

Please sign in to comment.