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

Commit bb5e32a

Browse files
committed
Enabling POST method options
1 parent d22fe16 commit bb5e32a

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

@@ -39,6 +41,7 @@ internal static partial class CURLoption
3941
internal const int CURLOPT_PROXY = CurlOptionObjectPointBase + 4;
4042
internal const int CURLOPT_PROXYUSERPWD = CurlOptionObjectPointBase + 6;
4143
internal const int CURLOPT_READDATA = CurlOptionObjectPointBase + 9;
44+
internal const int CURLOPT_POSTFIELDS = CurlOptionObjectPointBase + 15;
4245
internal const int CURLOPT_COOKIE = CurlOptionObjectPointBase + 22;
4346
internal const int CURLOPT_HTTPHEADER = CurlOptionObjectPointBase + 23;
4447
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
@@ -434,14 +434,24 @@ private SafeCurlHandle CreateRequestHandle(RequestCompletionSource state, GCHand
434434
// Set maximum automatic redirection option
435435
SetCurlOption(requestHandle, CURLoption.CURLOPT_MAXREDIRS, _maxAutomaticRedirections);
436436
}
437-
if (state.RequestMessage.Content != null)
437+
438+
if (state.RequestMessage.Method == HttpMethod.Put)
438439
{
439440
SetCurlOption(requestHandle, CURLoption.CURLOPT_UPLOAD, 1L);
440441
}
441-
if (state.RequestMessage.Method == HttpMethod.Head)
442+
else if (state.RequestMessage.Method == HttpMethod.Head)
442443
{
443444
SetCurlOption(requestHandle, CURLoption.CURLOPT_NOBODY, 1L);
444445
}
446+
else if (state.RequestMessage.Method == HttpMethod.Post)
447+
{
448+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POST, 1L);
449+
if (state.RequestMessage.Content == null)
450+
{
451+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POSTFIELDSIZE, 0L);
452+
SetCurlOption(requestHandle, CURLoption.CURLOPT_POSTFIELDS, "");
453+
}
454+
}
445455

446456
IntPtr statePtr = GCHandle.ToIntPtr(stateHandle);
447457
SetCurlOption(requestHandle, CURLoption.CURLOPT_PRIVATE, statePtr);

0 commit comments

Comments
 (0)