Azure / azure-storage-cpplite

Lite version of C++ Client Library for Microsoft Azure Storage
MIT License
25 stars 43 forks source link

curl postfields to request body are not passing thru #82

Open NaraVen opened 3 years ago

NaraVen commented 3 years ago

The lib_curl_http.h file in the include dir needs an extra setting to allow POSTFields to be passed to the body of the request. SPN token only works if we post the client_credential params to the body of the message not as params. In http://github.com/azure/azure-storage-fuse We added this line to get the above working. check_code(curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, nullptr)); // CURL won't actually read data on POSTs unless this is explicitly set.

See our working method below.

void set_input_stream(storage_istream s) override { m_input_stream = s; check_code(curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, read)); check_code(curl_easy_setopt(m_curl, CURLOPT_READDATA, this)); check_code(curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, nullptr)); // CURL won't actually read data on POSTs unless this is explicitly set. }

Jinming-Hu commented 3 years ago

Hi @NaraVen Can you elaborate what you're trying to do here? Do you want to add a new API? I'm almost sure the way you're doing it is wrong.

NaraVen commented 3 years ago

No new API. I am trying to add key-value pairs to the http request body. It is not working unless I change the cpplite libcurl_http_client.h set_input_stream method to add the line below. check_code(curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, nullptr)); // CURL won't actually read data on POSTs unless this is explicitly set.

My code in lines 460 - 464 in https://github.com/Azure/azure-storage-fuse/blob/master/blobfuse/src/OAuthTokenCredentialManager.cpp

is not getting set unless I change libcurl_http_client.h to include the POSTFIELDS line above.\

Jinming-Hu commented 3 years ago

@NaraVen Hi, I just tried current implementation with POST request. You're right, it won't send POST request body. I tried to add this line

check_code(curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, nullptr));

after this line https://github.com/Azure/azure-storage-cpplite/blob/a3a9c21de3fa9932dcfceb2b6617757a511c75c3/src/http/libcurl_http_client.cpp#L49

then it works.

Jinming-Hu commented 3 years ago

@NaraVen Do you want to create a PR so that you can get the credit?

NaraVen commented 3 years ago

sure, I will pull a PR. Thank you for looking into this.