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

Commit 18ccd53

Browse files
committed
Merge pull request #2840 from shrutigarg/latest
Enabling POST method options
2 parents 5059d97 + bb5e32a commit 18ccd53

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Common/src/Interop/Unix/libcurl/Interop.libcurl_types.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ internal static partial class CURLoption
2929

3030
internal const int CURLOPT_NOBODY = CurlOptionLongBase + 44;
3131
internal const int CURLOPT_UPLOAD = CurlOptionLongBase + 46;
32+
internal const int CURLOPT_POST = CurlOptionLongBase + 47;
3233
internal const int CURLOPT_FOLLOWLOCATION = CurlOptionLongBase + 52;
3334
internal const int CURLOPT_PROXYPORT = CurlOptionLongBase + 59;
35+
internal const int CURLOPT_POSTFIELDSIZE = CurlOptionLongBase + 60;
3436
internal const int CURLOPT_MAXREDIRS = CurlOptionLongBase + 68;
3537
internal const int CURLOPT_PROXYTYPE = CurlOptionLongBase + 101;
3638
internal const int CURLOPT_HTTPAUTH = CurlOptionLongBase + 107;
@@ -40,6 +42,7 @@ internal static partial class CURLoption
4042
internal const int CURLOPT_PROXY = CurlOptionObjectPointBase + 4;
4143
internal const int CURLOPT_PROXYUSERPWD = CurlOptionObjectPointBase + 6;
4244
internal const int CURLOPT_READDATA = CurlOptionObjectPointBase + 9;
45+
internal const int CURLOPT_POSTFIELDS = CurlOptionObjectPointBase + 15;
4346
internal const int CURLOPT_COOKIE = CurlOptionObjectPointBase + 22;
4447
internal const int CURLOPT_HTTPHEADER = CurlOptionObjectPointBase + 23;
4548
internal const int CURLOPT_HEADERDATA = CurlOptionObjectPointBase + 29;

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,24 @@ private SafeCurlHandle CreateRequestHandle(RequestCompletionSource state, GCHand
462462
// Set maximum automatic redirection option
463463
SetCurlOption(requestHandle, CURLoption.CURLOPT_MAXREDIRS, _maxAutomaticRedirections);
464464
}
465-
if (state.RequestMessage.Content != null)
465+
466+
if (state.RequestMessage.Method == HttpMethod.Put)
466467
{
467468
SetCurlOption(requestHandle, CURLoption.CURLOPT_UPLOAD, 1L);
468469
}
469-
if (state.RequestMessage.Method == HttpMethod.Head)
470+
else if (state.RequestMessage.Method == HttpMethod.Head)
470471
{
471472
SetCurlOption(requestHandle, CURLoption.CURLOPT_NOBODY, 1L);
472473
}
474+
else if (state.RequestMessage.Method == HttpMethod.Post)
475+
{
476+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POST, 1L);
477+
if (state.RequestMessage.Content == null)
478+
{
479+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POSTFIELDSIZE, 0L);
480+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POSTFIELDS, "");
481+
}
482+
}
473483

474484
IntPtr statePtr = GCHandle.ToIntPtr(stateHandle);
475485
SetCurlOption(requestHandle, CURLoption.CURLOPT_PRIVATE, statePtr);

0 commit comments

Comments
 (0)