Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 19f09c7

Browse files
committed
Fix HttpClient on Unix handling of 0-len content with chunked upload
1 parent d0803ba commit 19f09c7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.EasyRequest.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ internal void InitializeCurl()
9797
SetCurlOption(CURLoption.CURLOPT_VERBOSE, 1L);
9898
}
9999

100+
// Before actually configuring the handle based on the state of the request,
101+
// do any necessary cleanup of the request object.
102+
SanitizeRequestMessage();
103+
100104
// Configure the handle
101105
SetUrl();
102106
SetNetworkingOptions();
@@ -245,6 +249,15 @@ public void Cleanup() // not called Dispose because the request may still be in
245249
_sendTransferState?.Dispose();
246250
}
247251

252+
private void SanitizeRequestMessage()
253+
{
254+
// Make sure Transfer-Encoding and Content-Length make sense together.
255+
if (_requestMessage.Content != null)
256+
{
257+
SetChunkedModeForSend(_requestMessage);
258+
}
259+
}
260+
248261
private void SetUrl()
249262
{
250263
Uri requestUri = _requestMessage.RequestUri;
@@ -692,8 +705,6 @@ internal void SetRequestHeaders()
692705
// Add content request headers
693706
if (_requestMessage.Content != null)
694707
{
695-
SetChunkedModeForSend(_requestMessage);
696-
697708
AddRequestHeaders(_requestMessage.Content.Headers, slist);
698709

699710
if (_requestMessage.Content.Headers.ContentType == null)

src/System.Net.Http/tests/FunctionalTests/PostScenarioTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ public async Task PostEmptyContentUsingChunkedEncoding_Success(Uri serverUri)
6969
useContentLengthUpload: false, useChunkedEncodingUpload: true);
7070
}
7171

72+
[OuterLoop] // TODO: Issue #11345
73+
[Theory, MemberData(nameof(EchoServers))]
74+
public async Task PostEmptyContentUsingConflictingSemantics_Success(Uri serverUri)
75+
{
76+
await PostHelper(serverUri, string.Empty, new StringContent(string.Empty),
77+
useContentLengthUpload: true, useChunkedEncodingUpload: true);
78+
}
79+
7280
[OuterLoop] // TODO: Issue #11345
7381
[Theory, MemberData(nameof(EchoServers))]
7482
public async Task PostUsingContentLengthSemantics_Success(Uri serverUri)

0 commit comments

Comments
 (0)