lib/curl/Request: remove redundant CurlEasy wrapper methods

This commit is contained in:
Max Kellermann 2023-12-09 20:47:32 +01:00
parent e9c40dead8
commit 642de1510b
5 changed files with 32 additions and 44 deletions

View File

@ -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,7 +543,7 @@ CurlInputStream::SeekInternal(offset_type new_offset)
/* send the "Range" header */
if (offset > 0)
request->SetOption(CURLOPT_RANGE,
request->GetEasy().SetOption(CURLOPT_RANGE,
fmt::format_int{offset}.c_str());
StartRequest();

View File

@ -109,7 +109,7 @@ QobuzLoginRequest::QobuzLoginRequest(CurlGlobal &curl,
:request(curl, *this),
handler(_handler)
{
request.SetUrl(MakeLoginUrl(request.Get(), base_url, app_id,
request.GetEasy().SetURL(MakeLoginUrl(request.Get(), base_url, app_id,
username, email, password,
device_manufacturer_id).c_str());
}

View File

@ -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

View File

@ -1,14 +1,11 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>
#ifndef CURL_REQUEST_HXX
#define CURL_REQUEST_HXX
#pragma once
#include "Easy.hxx"
#include "Adapter.hxx"
#include <cstddef>
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<typename T>
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

View File

@ -31,6 +31,8 @@
#include <string>
#include <utility>
using std::string_view_literals::operator""sv;
class CurlStorage final : public Storage {
const std::string base;
@ -244,21 +246,22 @@ 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,
"<?xml version=\"1.0\"?>\n"
easy.SetRequestBody("<?xml version=\"1.0\"?>\n"
"<a:propfind xmlns:a=\"DAV:\">"
"<a:prop>"
"<a:resourcetype/>"
@ -266,7 +269,7 @@ public:
"<a:getcontentlength/>"
"<a:getlastmodified/>"
"</a:prop>"
"</a:propfind>");
"</a:propfind>"sv);
}
using BlockingHttpRequest::GetEasy;