diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 320f0a7e9..b5660c3ad 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -456,7 +456,7 @@ CurlInputStream::~CurlInputStream() noexcept } static CurlEasy -CreateEasy(const char *url) +CreateEasy(const char *url, struct curl_slist *headers) { CurlEasy easy{url}; @@ -503,14 +503,17 @@ CreateEasy(const char *url) easy.SetOption(CURLOPT_TCP_KEEPIDLE, tcp_keepidle); easy.SetOption(CURLOPT_TCP_KEEPINTVL, tcp_keepintvl); + easy.SetRequestHeaders(headers); + return easy; } void CurlInputStream::InitEasy() { - request = new CurlRequest(**curl_init, CreateEasy(GetURI()), *this); - request->SetRequestHeaders(request_headers.Get()); + request = new CurlRequest(**curl_init, + CreateEasy(GetURI(), request_headers.Get()), + *this); } void @@ -540,8 +543,8 @@ CurlInputStream::SeekInternal(offset_type new_offset) /* send the "Range" header */ if (offset > 0) - request->SetOption(CURLOPT_RANGE, - fmt::format_int{offset}.c_str()); + request->GetEasy().SetOption(CURLOPT_RANGE, + fmt::format_int{offset}.c_str()); StartRequest(); } diff --git a/src/input/plugins/QobuzLoginRequest.cxx b/src/input/plugins/QobuzLoginRequest.cxx index 10c260490..2eb412c46 100644 --- a/src/input/plugins/QobuzLoginRequest.cxx +++ b/src/input/plugins/QobuzLoginRequest.cxx @@ -109,9 +109,9 @@ QobuzLoginRequest::QobuzLoginRequest(CurlGlobal &curl, :request(curl, *this), handler(_handler) { - request.SetUrl(MakeLoginUrl(request.Get(), base_url, app_id, - username, email, password, - device_manufacturer_id).c_str()); + request.GetEasy().SetURL(MakeLoginUrl(request.Get(), base_url, app_id, + username, email, password, + device_manufacturer_id).c_str()); } QobuzLoginRequest::~QobuzLoginRequest() noexcept diff --git a/src/input/plugins/QobuzTrackRequest.cxx b/src/input/plugins/QobuzTrackRequest.cxx index f0ddb6090..839dc1e0d 100644 --- a/src/input/plugins/QobuzTrackRequest.cxx +++ b/src/input/plugins/QobuzTrackRequest.cxx @@ -69,7 +69,7 @@ QobuzTrackRequest::QobuzTrackRequest(QobuzClient &client, { request_headers.Append(("X-User-Auth-Token:" + session.user_auth_token).c_str()); - request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get()); + request.GetEasy().SetRequestHeaders(request_headers.Get()); } QobuzTrackRequest::~QobuzTrackRequest() noexcept diff --git a/src/lib/curl/Request.hxx b/src/lib/curl/Request.hxx index 929968acc..42dd94df8 100644 --- a/src/lib/curl/Request.hxx +++ b/src/lib/curl/Request.hxx @@ -1,14 +1,11 @@ // SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann -#ifndef CURL_REQUEST_HXX -#define CURL_REQUEST_HXX +#pragma once #include "Easy.hxx" #include "Adapter.hxx" -#include - class CurlGlobal; class CurlResponseHandler; @@ -38,7 +35,7 @@ public: CurlRequest(CurlGlobal &_global, const char *url, CurlResponseHandler &_handler) :CurlRequest(_global, _handler) { - SetUrl(url); + easy.SetURL(url); } ~CurlRequest() noexcept; @@ -84,19 +81,6 @@ public: return easy; } - template - void SetOption(CURLoption option, T value) { - easy.SetOption(option, value); - } - - void SetUrl(const char *url) { - easy.SetURL(url); - } - - void SetRequestHeaders(struct curl_slist *request_headers) { - easy.SetRequestHeaders(request_headers); - } - void Resume() noexcept; /** @@ -113,5 +97,3 @@ private: */ void FreeEasy() noexcept; }; - -#endif diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 9c5a297ac..1f9987939 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -31,6 +31,8 @@ #include #include +using std::string_view_literals::operator""sv; + class CurlStorage final : public Storage { const std::string base; @@ -244,29 +246,30 @@ public: :BlockingHttpRequest(_curl, _uri), CommonExpatParser(ExpatNamespaceSeparator{'|'}) { - request.SetOption(CURLOPT_CUSTOMREQUEST, "PROPFIND"); - request.SetOption(CURLOPT_FOLLOWLOCATION, 1L); - request.SetOption(CURLOPT_MAXREDIRS, 1L); + auto &easy = request.GetEasy(); + + easy.SetOption(CURLOPT_CUSTOMREQUEST, "PROPFIND"); + easy.SetOption(CURLOPT_FOLLOWLOCATION, 1L); + easy.SetOption(CURLOPT_MAXREDIRS, 1L); /* this option eliminates the probe request when username/password are specified */ - request.SetOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + easy.SetOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC); request_headers.Append(FmtBuffer<40>("depth: {}", depth)); request_headers.Append("content-type: text/xml"); - request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get()); + easy.SetRequestHeaders(request_headers.Get()); - request.SetOption(CURLOPT_POSTFIELDS, - "\n" - "" - "" - "" - "" - "" - "" - "" - ""); + easy.SetRequestBody("\n" + "" + "" + "" + "" + "" + "" + "" + ""sv); } using BlockingHttpRequest::GetEasy;