From 55688a25aa87d3357c7334e1e4dfd90caf1a67d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Wed, 30 Aug 2023 00:11:00 -0400 Subject: [PATCH] http: don't encode whole url url encoding should be used for url components by users of the library, otherwise characters like '/' get escaped. --- include/opendht/http.h | 2 +- src/http.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/opendht/http.h b/include/opendht/http.h index 444fa16d..7c26a93f 100644 --- a/include/opendht/http.h +++ b/include/opendht/http.h @@ -330,7 +330,7 @@ private: void build(); - static std::string url_encode(const std::string& value); + static std::string url_encode(std::string_view value); void init_default_headers(); /** diff --git a/src/http.cpp b/src/http.cpp index 94021519..6b7d4aad 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -1052,7 +1052,7 @@ Request::build() bool append_body = !body_.empty(); // first header - request << header_.method().c_str() << " " << url_encode(header_.request_target()) << " " << + request << header_.method().c_str() << " " << header_.request_target() << " " << "HTTP/" << header_.http_major() << "." << header_.http_minor() << "\r\n"; // other headers @@ -1090,7 +1090,7 @@ Request::build() // https://stackoverflow.com/a/17708801 std::string -Request::url_encode(const std::string& value) +Request::url_encode(std::string_view value) { std::ostringstream escaped; escaped.fill('0'); @@ -1317,7 +1317,7 @@ Request::post() init_parser(); if (logger_) - logger_->d("[http:request:%i] sending %zu bytes", id_, request_.size()); + logger_->debug("[http:request:{}] sending {} bytes", id_, request_.size()); // write the request to buffer std::ostream request_stream(&conn_->input());