From b291110ffa56903191aeb553746adaf87dd3064e Mon Sep 17 00:00:00 2001 From: tankorsmash Date: Sun, 16 Mar 2025 12:18:34 -0400 Subject: [PATCH] fix POST data not working without string literals https://curl.se/libcurl/c/curl_easy_setopt.html Strings passed to libcurl as 'char *' arguments, are copied by the library; the string storage associated to the pointer argument may be discarded or reused after curl_easy_setopt returns. The only exception to this rule is really CURLOPT_POSTFIELDS --- curl.bqn | 2 +- ffi.bqn | 1 + tests.bqn | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/curl.bqn b/curl.bqn index 4533f00..a2a0963 100644 --- a/curl.bqn +++ b/curl.bqn @@ -116,8 +116,8 @@ SetTimeoutms←{timeoutms 𝕊 session: # Use a POST method and set data to post SetData←{data 𝕊 session: "setting up POST request"Check EasySetoptLong⟨session.sessionPtr,curlOptions.post,1⟩ - "setting POST data"Check EasySetoptStr⟨session.sessionPtr,curlOptions.postfields,data⟩ "setting POST data size"Check EasySetoptLong⟨session.sessionPtr,curlOptions.postfieldsize,≠data⟩ + "copying POST data"Check EasySetoptStr⟨session.sessionPtr,curlOptions.copypostfields,data⟩ session } diff --git a/ffi.bqn b/ffi.bqn index ce3aeae..8e062aa 100644 --- a/ffi.bqn +++ b/ffi.bqn @@ -62,6 +62,7 @@ curlOptions←{ # long integer options postfieldsize⇐60 # size of the POST input data + copypostfields⇐10165 # copy POST input data timeout⇐78 # timeout in seconds timeoutms⇐155 # timeout in milliseconds diff --git a/tests.bqn b/tests.bqn index 73db3fa..4db5dcf 100755 --- a/tests.bqn +++ b/tests.bqn @@ -36,7 +36,7 @@ simpleAPI_testsuite←⟨ }, "simple POST with headers"‿{𝕊𝕩: headers←⟨"Content-Type: application/json"⟩ - r←headers Post ⟨httpbinURL∾"/post","{""key"": ""value""}"⟩ + r←headers Post ⟨httpbinURL∾"/post",¯1000 + 1000 + "{""key"": 1}"⟩ ! 200=r.code ! 0=r.redirectCount ! 1=⊑"HTTP/"⍷r.headers