Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade/remove dependency curl-ev and migrating some deprecation cURL… #883

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/include/userver/clients/http/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Client final {
friend class impl::EasyWrapper;
void IncPending() noexcept { ++pending_tasks_; }
void DecPending() noexcept { --pending_tasks_; }

void PushIdleEasy(std::shared_ptr<curl::easy>&& easy) noexcept;

std::shared_ptr<curl::easy> TryDequeueIdle() noexcept;
Expand Down
9 changes: 2 additions & 7 deletions core/include/userver/clients/http/form.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ class Form final {
void AddContent(std::string_view key, std::string_view content, const std::string& content_type);

void AddBuffer(const std::string& key, const std::string& file_name, const std::shared_ptr<std::string>& buffer);
void AddBuffer(
const std::string& key,
const std::string& file_name,
const std::shared_ptr<std::string>& buffer,
const std::string& content_type
);

void AddBuffer(const std::string& key, const std::string& file_name, const std::shared_ptr<std::string>& buffer, const std::string& content_type);

/// @cond
// Call of this method will invalidate the form
Expand All @@ -40,7 +36,6 @@ class Form final {
private:
std::unique_ptr<curl::form> impl_;
};

} // namespace clients::http

USERVER_NAMESPACE_END
39 changes: 39 additions & 0 deletions core/include/userver/clients/http/mime.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <curl-ev/mime.hpp>

USERVER_NAMESPACE_BEGIN

namespace curl {
class mime;
}

namespace clients::http {
class Mime final {
public:
Mime();
~Mime();

Mime(const Mime&) = delete;
Mime(Mime&&) noexcept;

Mime& operator= (const Mime&) = delete;
Mime& operator= (Mime&&) noexcept;

public:
void AddContent(std::string_view key, std::string_view content);
void AddContent(std::string_view key, std::string_view content, std::string_view content_type);

void AddBuffer(std::string_view key, std::string_view name, const std::shared_ptr<std::string>& buffer);
void AddBuffer(std::string_view key, std::string_view name, std::string_view content_type, const std::shared_ptr<std::string>& buffer);

public:
std::unique_ptr<curl::mime> GetNative() &&;

private:
std::unique_ptr<curl::mime> mime_;

};
}

USERVER_NAMESPACE_END
9 changes: 8 additions & 1 deletion core/include/userver/clients/http/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RequestState;
class StreamedResponse;
class ConnectTo;
class Form;
class Mime;
struct DeadlinePropagationConfig;
class RequestStats;
class DestinationStatistics;
Expand Down Expand Up @@ -114,6 +115,9 @@ class Request final {
/// POST request with url and multipart/form-data
Request& post(std::string url, Form&& form) &;
Request post(std::string url, Form&& form) &&;
/// POST request with url and mime
Request& post(std::string url, Mime&& mime) &;
Request post(std::string url, Mime&& mime) &&;
/// PUT request
Request& put() &;
Request put() &&;
Expand Down Expand Up @@ -148,9 +152,12 @@ class Request final {
/// data for POST request
Request& data(std::string data) &;
Request data(std::string data) &&;
/// form for POST request
/// form POST request
Request& form(Form&& form) &;
Request form(Form&& form) &&;
// mime for POST request
Request& mime(Mime&& mime) &;
Request mime(Mime&& mime) &&;
/// Headers for request as map
Request& headers(const Headers& headers) &;
Request headers(const Headers& headers) &&;
Expand Down
2 changes: 1 addition & 1 deletion core/src/clients/http/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Request Client::CreateRequest() {

try {
auto wrapper = engine::AsyncNoSpan(fs_task_processor_, [this, &multi] {
return impl::EasyWrapper{easy_.Get()->GetBoundBlocking(*multi), *this};
return impl::EasyWrapper { easy_.Get()->GetBoundBlocking(*multi), *this };
}).Get();
return Request{
std::move(wrapper),
Expand Down
4 changes: 0 additions & 4 deletions core/src/clients/http/easy_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ EasyWrapper::~EasyWrapper() {
}
}

curl::easy& EasyWrapper::Easy() { return *easy_; }

const curl::easy& EasyWrapper::Easy() const { return *easy_; }

} // namespace clients::http::impl

USERVER_NAMESPACE_END
5 changes: 3 additions & 2 deletions core/src/clients/http/easy_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ class EasyWrapper final {

~EasyWrapper();

curl::easy& Easy();
const curl::easy& Easy() const;
inline curl::easy& Easy() { return *easy_; }
inline const curl::easy& Easy() const { return *easy_; };

private:
//std::shared_ptr<curl::easy> easy_;
std::shared_ptr<curl::easy> easy_;
Client& client_;
};
Expand Down
10 changes: 3 additions & 7 deletions core/src/clients/http/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ USERVER_NAMESPACE_BEGIN

namespace clients::http {

Form::Form() : impl_(std::make_unique<curl::form>()) {}
Form::Form() : impl_(std::make_unique<curl::form>()) { }
Form::~Form() = default;
Form::Form(Form&&) noexcept = default;
Form& Form::operator=(Form&&) noexcept = default;
Expand All @@ -21,12 +21,8 @@ void Form::AddBuffer(const std::string& key, const std::string& file_name, const
impl_->add_buffer(key, file_name, buffer);
}

void Form::AddBuffer(
const std::string& key,
const std::string& file_name,
const std::shared_ptr<std::string>& buffer,
const std::string& content_type
) {
void Form::AddBuffer(const std::string& key, const std::string& file_name,
const std::shared_ptr<std::string>& buffer, const std::string& content_type) {
impl_->add_buffer(key, file_name, buffer, content_type);
}

Expand Down
37 changes: 37 additions & 0 deletions core/src/clients/http/mime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <userver/clients/http/mime.hpp>

USERVER_NAMESPACE_BEGIN

namespace clients::http {
Mime::Mime() {

}

Mime::~Mime() {

}

Mime::Mime(Mime&&) noexcept = default;
Mime& Mime::operator= (Mime&&) noexcept = default;

std::unique_ptr<curl::mime> Mime::GetNative() && { return std::move(mime_); }

void Mime::AddContent(std::string_view key, std::string_view content) {
mime_->add_content(key, content);
}

void Mime::AddContent(std::string_view key, std::string_view content, std::string_view content_type) {
mime_->add_content(key, content, content_type);
}

void Mime::AddBuffer(std::string_view key, std::string_view name, const std::shared_ptr<std::string>& buffer) {
mime_->add_buffer(key, name, buffer);
}

void Mime::AddBuffer(std::string_view key, std::string_view name, std::string_view content_type, const std::shared_ptr<std::string>& buffer) {
mime_->add_buffer(key, name, content_type, buffer);
}

} // namespace clients::http

USERVER_NAMESPACE_END
8 changes: 6 additions & 2 deletions core/src/clients/http/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ void PluginRequest::SetHeader(std::string_view name, std::string_view value) {
void PluginRequest::AddQueryParams(std::string_view params) {
const auto& url = state_.easy().get_original_url();
if (url.find('?') != std::string::npos) {
state_.easy().set_url(utils::StrCat(url, "&", params));
std::error_code ec;
state_.easy().set_url(utils::StrCat(url, "&", params), ec);
UASSERT_MSG(!ec, "set_url filed!");
} else {
state_.easy().set_url(utils::StrCat(url, "?", params));
std::error_code ec;
state_.easy().set_url(utils::StrCat(url, "?", params), ec);
UASSERT_MSG(!ec, "set_url filed!");
}
}

Expand Down
61 changes: 37 additions & 24 deletions core/src/clients/http/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <userver/clients/http/connect_to.hpp>
#include <userver/clients/http/error.hpp>
#include <userver/clients/http/form.hpp>
#include <userver/clients/http/mime.hpp>
#include <userver/clients/http/response_future.hpp>
#include <userver/clients/http/streamed_response.hpp>
#include <userver/concurrent/queue.hpp>
Expand Down Expand Up @@ -75,21 +76,21 @@ constexpr utils::TrivialBiMap kAuthTypeMap = [](auto selector) {
curl::easy::httpauth_t HttpAuthTypeToNative(HttpAuthType value) {
switch (value) {
case HttpAuthType::kBasic:
return curl::easy::auth_basic;
return curl::easy::httpauth_t::auth_basic;
case HttpAuthType::kDigest:
return curl::easy::auth_digest;
return curl::easy::httpauth_t::auth_digest;
case HttpAuthType::kDigestIE:
return curl::easy::auth_digest_ie;
return curl::easy::httpauth_t::auth_digest_ie;
case HttpAuthType::kNegotiate:
return curl::easy::auth_negotiate;
return curl::easy::httpauth_t::auth_negotiate;
case HttpAuthType::kNtlm:
return curl::easy::auth_ntlm;
return curl::easy::httpauth_t::auth_ntlm;
case HttpAuthType::kNtlmWb:
return curl::easy::auth_ntlm_wb;
return curl::easy::httpauth_t::auth_ntlm_wb;
case HttpAuthType::kAny:
return curl::easy::auth_any;
return curl::easy::httpauth_t::auth_any;
case HttpAuthType::kAnySafe:
return curl::easy::auth_any_safe;
return curl::easy::httpauth_t::auth_any_safe;
}

UINVARIANT(false, "Unexpected http auth type");
Expand All @@ -98,23 +99,23 @@ curl::easy::httpauth_t HttpAuthTypeToNative(HttpAuthType value) {
curl::easy::proxyauth_t ProxyAuthTypeToNative(ProxyAuthType value) {
switch (value) {
case ProxyAuthType::kBasic:
return curl::easy::proxy_auth_basic;
return curl::easy::proxyauth_t::proxy_auth_basic;
case ProxyAuthType::kDigest:
return curl::easy::proxy_auth_digest;
return curl::easy::proxyauth_t::proxy_auth_digest;
case ProxyAuthType::kDigestIE:
return curl::easy::proxy_auth_digest_ie;
return curl::easy::proxyauth_t::proxy_auth_digest_ie;
case ProxyAuthType::kBearer:
return curl::easy::proxy_auth_bearer;
return curl::easy::proxyauth_t::proxy_auth_bearer;
case ProxyAuthType::kNegotiate:
return curl::easy::proxy_auth_negotiate;
return curl::easy::proxyauth_t::proxy_auth_negotiate;
case ProxyAuthType::kNtlm:
return curl::easy::proxy_auth_ntlm;
return curl::easy::proxyauth_t::proxy_auth_ntlm;
case ProxyAuthType::kNtlmWb:
return curl::easy::proxy_auth_ntlm_wb;
return curl::easy::proxyauth_t::proxy_auth_ntlm_wb;
case ProxyAuthType::kAny:
return curl::easy::proxy_auth_any;
return curl::easy::proxyauth_t::proxy_auth_any;
case ProxyAuthType::kAnySafe:
return curl::easy::proxy_auth_anysafe;
return curl::easy::proxyauth_t::proxy_auth_anysafe;
}

UINVARIANT(false, "Unexpected proxy auth type");
Expand All @@ -124,9 +125,9 @@ bool IsUserAgentHeader(std::string_view header_name) {
return utils::StrIcaseEqual{}(header_name, USERVER_NAMESPACE::http::headers::kUserAgent);
}

void SetUserAgent(curl::easy& easy, const std::string& value) { easy.set_user_agent(value); }
void SetUserAgent(curl::easy& easy, const std::string& value) { easy.set_user_agent(std::string_view(value)); }

void SetUserAgent(curl::easy& easy, std::string_view value) { easy.set_user_agent(std::string{value}); }
void SetUserAgent(curl::easy& easy, std::string_view value) { easy.set_user_agent(value); }

template <class Range>
void SetHeaders(curl::easy& easy, const Range& headers_range) {
Expand All @@ -148,7 +149,7 @@ void SetCookies(curl::easy& easy, const Range& cookies_range) {
cookie_str += '=';
cookie_str += value;
}
easy.set_cookie(cookie_str);
easy.set_cookie(std::string_view(cookie_str));
}

template <class Range>
Expand Down Expand Up @@ -323,13 +324,13 @@ Request& Request::unix_socket_path(const std::string& path) & {
Request Request::unix_socket_path(const std::string& path) && { return std::move(this->unix_socket_path(path)); }

Request& Request::use_ipv4() & {
pimpl_->easy().set_ip_resolve(curl::easy::ip_resolve_v4);
pimpl_->easy().set_ip_resolve(curl::easy::ip_resolve_t::ip_resolve_v4);
return *this;
}
Request Request::use_ipv4() && { return std::move(this->use_ipv4()); }

Request& Request::use_ipv6() & {
pimpl_->easy().set_ip_resolve(curl::easy::ip_resolve_v6);
pimpl_->easy().set_ip_resolve(curl::easy::ip_resolve_t::ip_resolve_v6);
return *this;
}
Request Request::use_ipv6() && { return std::move(this->use_ipv6()); }
Expand All @@ -350,10 +351,19 @@ Request Request::data(std::string data) && { return std::move(this->data(std::mo
Request& Request::form(Form&& form) & {
pimpl_->easy().set_http_post(std::move(form).GetNative());
pimpl_->easy().add_header(kHeaderExpect, "", curl::easy::EmptyHeaderAction::kDoNotSend);
return *this;
return *this;
}

Request Request::form(Form&& form) && { return std::move(this->form(std::move(form))); }

Request& Request::mime(Mime&& mime) & {
pimpl_->easy().set_mimepost(std::move(mime).GetNative());
pimpl_->easy().add_header(kHeaderExpect, "", curl::easy::EmptyHeaderAction::kDoNotSend);
return *this;
}

Request Request::mime(Mime&& mime) && { return std::move(this->mime(std::move(mime))); };

Request& Request::headers(const Headers& headers) & {
SetHeaders(pimpl_->easy(), headers);
return *this;
Expand Down Expand Up @@ -393,7 +403,7 @@ Request Request::proxy_headers(const std::initializer_list<std::pair<std::string
}

Request& Request::user_agent(const std::string& value) & {
pimpl_->easy().set_user_agent(value.c_str());
pimpl_->easy().set_user_agent(std::string_view(value));
return *this;
}
Request Request::user_agent(const std::string& value) && { return std::move(this->user_agent(value)); }
Expand Down Expand Up @@ -492,6 +502,9 @@ Request Request::post(std::string url, Form&& form) && {
return std::move(this->post(std::move(url), std::move(form)));
}

Request& Request::post(std::string url, Mime&& mime) & { return this->url(std::move(url)).mime(std::move(mime)); }
Request Request::post(std::string url, Mime&& mime) && { return std::move(this->post(std::move(url), std::move(mime))); }

Request& Request::post(std::string url, std::string data) & {
return this->url(std::move(url)).data(std::move(data)).post();
}
Expand Down
Loading