summaryrefslogtreecommitdiff
path: root/src/mongo/util/net/http_client_curl.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/util/net/http_client_curl.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/util/net/http_client_curl.cpp')
-rw-r--r--src/mongo/util/net/http_client_curl.cpp100
1 files changed, 14 insertions, 86 deletions
diff --git a/src/mongo/util/net/http_client_curl.cpp b/src/mongo/util/net/http_client_curl.cpp
index 9db3c06f73f..fa1834c8bde 100644
--- a/src/mongo/util/net/http_client_curl.cpp
+++ b/src/mongo/util/net/http_client_curl.cpp
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kNetwork
-
#include "mongo/platform/basic.h"
#include <cstddef>
@@ -49,24 +47,22 @@
#include "mongo/db/commands/server_status.h"
#include "mongo/executor/connection_pool.h"
#include "mongo/executor/connection_pool_stats.h"
-#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/unordered_map.h"
#include "mongo/transport/transport_layer.h"
#include "mongo/util/alarm.h"
#include "mongo/util/alarm_runner_background_thread.h"
#include "mongo/util/assert_util.h"
-#include "mongo/util/bufreader.h"
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/util/functional.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/net/http_client.h"
-#include "mongo/util/net/http_client_options.h"
#include "mongo/util/processinfo.h"
#include "mongo/util/strong_weak_finish_line.h"
#include "mongo/util/system_clock_source.h"
#include "mongo/util/timer.h"
+
namespace mongo {
namespace {
@@ -163,40 +159,20 @@ size_t WriteMemoryCallback(void* ptr, size_t size, size_t nmemb, void* data) {
*/
size_t ReadMemoryCallback(char* buffer, size_t size, size_t nitems, void* instream) {
- auto* bufReader = reinterpret_cast<BufReader*>(instream);
+ auto* cdrc = reinterpret_cast<ConstDataRangeCursor*>(instream);
size_t ret = 0;
- if (bufReader->remaining() > 0) {
- size_t readSize =
- std::min(size * nitems, static_cast<unsigned long>(bufReader->remaining()));
- auto buf = bufReader->readBytes(readSize);
- memcpy(buffer, buf.rawData(), readSize);
+ if (cdrc->length() > 0) {
+ size_t readSize = std::min(size * nitems, cdrc->length());
+ memcpy(buffer, cdrc->data(), readSize);
+ invariant(cdrc->advanceNoThrow(readSize).isOK());
ret = readSize;
}
return ret;
}
-/**
- * Seek into for data to the remote side
- */
-size_t SeekMemoryCallback(void* clientp, curl_off_t offset, int origin) {
-
- // Curl will call this in readrewind but only to reset the stream to the beginning
- // In other protocols (like FTP, SSH) or HTTP resumption they may ask for partial buffers which
- // we do not support.
- if (offset != 0 || origin != SEEK_SET) {
- return CURL_SEEKFUNC_CANTSEEK;
- }
-
- auto* bufReader = reinterpret_cast<BufReader*>(clientp);
-
- bufReader->rewindToStart();
-
- return CURL_SEEKFUNC_OK;
-}
-
struct CurlEasyCleanup {
void operator()(CURL* handle) {
if (handle) {
@@ -220,47 +196,6 @@ long longSeconds(Seconds tm) {
return static_cast<long>(durationCount<Seconds>(tm));
}
-
-StringData enumToString(curl_infotype type) {
- switch (type) {
- case CURLINFO_TEXT:
- return "TEXT"_sd;
- case CURLINFO_HEADER_IN:
- return "HEADER_IN"_sd;
- case CURLINFO_HEADER_OUT:
- return "HEADER_OUT"_sd;
- case CURLINFO_DATA_IN:
- return "DATA_IN"_sd;
- case CURLINFO_DATA_OUT:
- return "DATA_OUT"_sd;
- case CURLINFO_SSL_DATA_IN:
- return "SSL_DATA_IN"_sd;
- case CURLINFO_SSL_DATA_OUT:
- return "SSL_DATA_OUT"_sd;
- default:
- return "unknown"_sd;
- }
-}
-
-int curlDebugCallback(CURL* handle, curl_infotype type, char* data, size_t size, void* clientp) {
- switch (type) {
- case CURLINFO_TEXT:
- case CURLINFO_HEADER_IN:
- case CURLINFO_HEADER_OUT:
- case CURLINFO_DATA_IN:
- case CURLINFO_DATA_OUT:
- LOGV2_DEBUG(7661901,
- 1,
- "Curl",
- "type"_attr = enumToString(type),
- "message"_attr = StringData(data, size));
- [[fallthrough]];
-
- default:
- return 0;
- }
-}
-
CurlEasyHandle createCurlEasyHandle(Protocols protocol) {
CurlEasyHandle handle(curl_easy_init());
uassert(ErrorCodes::InternalError, "Curl initialization failed", handle);
@@ -291,10 +226,9 @@ CurlEasyHandle createCurlEasyHandle(Protocols protocol) {
}
// TODO: CURLOPT_EXPECT_100_TIMEOUT_MS?
- if (httpClientOptions.verboseLogging.loadRelaxed()) {
- curl_easy_setopt(handle.get(), CURLOPT_VERBOSE, 1);
- curl_easy_setopt(handle.get(), CURLOPT_DEBUGFUNCTION, curlDebugCallback);
- }
+ // TODO: consider making this configurable, defaults to stderr
+ // curl_easy_setopt(handle.get(), CURLOPT_VERBOSE, 1);
+ // curl_easy_setopt(_handle.get(), CURLOPT_DEBUGFUNCTION , ???);
return handle;
}
@@ -696,7 +630,7 @@ private:
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, longSeconds(_connectTimeout));
- BufReader bufReader(cdr.data(), cdr.length());
+ ConstDataRangeCursor cdrc(cdr);
switch (method) {
case HttpMethod::kGET:
uassert(ErrorCodes::BadValue,
@@ -711,22 +645,16 @@ private:
curl_easy_setopt(handle, CURLOPT_POST, 1);
curl_easy_setopt(handle, CURLOPT_READFUNCTION, ReadMemoryCallback);
- curl_easy_setopt(handle, CURLOPT_READDATA, &bufReader);
- curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, (long)bufReader.remaining());
-
- curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, SeekMemoryCallback);
- curl_easy_setopt(handle, CURLOPT_SEEKDATA, &bufReader);
+ curl_easy_setopt(handle, CURLOPT_READDATA, &cdrc);
+ curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, (long)cdrc.length());
break;
case HttpMethod::kPUT:
curl_easy_setopt(handle, CURLOPT_POST, 0);
curl_easy_setopt(handle, CURLOPT_PUT, 1);
curl_easy_setopt(handle, CURLOPT_READFUNCTION, ReadMemoryCallback);
- curl_easy_setopt(handle, CURLOPT_READDATA, &bufReader);
- curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (long)bufReader.remaining());
-
- curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, SeekMemoryCallback);
- curl_easy_setopt(handle, CURLOPT_SEEKDATA, &bufReader);
+ curl_easy_setopt(handle, CURLOPT_READDATA, &cdrc);
+ curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (long)cdrc.length());
break;
default:
MONGO_UNREACHABLE;