From 86deb574aa36ec3c65434b60cefd87f88633a12d Mon Sep 17 00:00:00 2001 From: danomatika Date: Wed, 16 Apr 2025 23:43:46 +0200 Subject: [PATCH] ofURLFileLoader: set POST opt before handling funcs, don't set POST handling if making a GET req --- libs/openFrameworks/utils/ofURLFileLoader.cpp | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/libs/openFrameworks/utils/ofURLFileLoader.cpp b/libs/openFrameworks/utils/ofURLFileLoader.cpp index 8449866074e..6c3506aa058 100644 --- a/libs/openFrameworks/utils/ofURLFileLoader.cpp +++ b/libs/openFrameworks/utils/ofURLFileLoader.cpp @@ -354,23 +354,6 @@ ofHttpResponse ofURLFileLoaderImpl::handleRequest(const ofHttpRequest & request) if (headers) { curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, headers); } - std::string body = request.body; - if (!request.body.empty()) { - if (request.method == ofHttpRequest::PUT || request.body.size() > MAX_POSTFIELDS_SIZE) { // If request is an upload (e.g., file upload) - curl_easy_setopt(curl.get(), CURLOPT_UPLOAD, 1L); - curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION, readBody_cb); - curl_easy_setopt(curl.get(), CURLOPT_READDATA, &body); - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, 0L); - } else { // If request is a normal POST - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, request.body.size()); - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, request.body.c_str()); - } - } else { - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, 0L); - curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, ""); - curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION, nullptr); - curl_easy_setopt(curl.get(), CURLOPT_READDATA, nullptr); - } if (request.method == ofHttpRequest::GET) { curl_easy_setopt(curl.get(), CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl.get(), CURLOPT_POST, 0L); @@ -386,6 +369,25 @@ ofHttpResponse ofURLFileLoaderImpl::handleRequest(const ofHttpRequest & request) curl_easy_setopt(curl.get(), CURLOPT_UPLOAD, 0L); curl_easy_setopt(curl.get(), CURLOPT_HTTPGET, 0L); } + if (request.method != ofHttpRequest::GET) { + std::string body = request.body; + if (!request.body.empty()) { + if (request.method == ofHttpRequest::PUT || request.body.size() > MAX_POSTFIELDS_SIZE) { // If request is an upload (e.g., file upload) + curl_easy_setopt(curl.get(), CURLOPT_UPLOAD, 1L); + curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION, readBody_cb); + curl_easy_setopt(curl.get(), CURLOPT_READDATA, &body); + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, 0L); + } else { // If request is a normal POST + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, request.body.size()); + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, request.body.c_str()); + } + } else { + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, 0L); + curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, ""); + curl_easy_setopt(curl.get(), CURLOPT_READFUNCTION, nullptr); + curl_easy_setopt(curl.get(), CURLOPT_READDATA, nullptr); + } + } if (request.timeoutSeconds > 0) { curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, request.timeoutSeconds);