Common/HttpRequest: Implement EscapeComponent

This commit is contained in:
spycrab 2019-03-30 14:49:18 +01:00
parent 0bce1c509d
commit 3dbf44417a
2 changed files with 12 additions and 0 deletions

View File

@ -36,6 +36,7 @@ public:
static int CurlProgressCallback(Impl* impl, double dlnow, double dltotal, double ulnow,
double ultotal);
const std::string EscapeComponent(const std::string& string);
private:
static std::mutex s_curl_was_inited_mutex;
@ -74,6 +75,11 @@ void HttpRequest::FollowRedirects(long max)
m_impl->FollowRedirects(max);
}
const std::string HttpRequest::EscapeComponent(const std::string& string)
{
return m_impl->EscapeComponent(string);
}
HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers)
{
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0);
@ -159,6 +165,11 @@ void HttpRequest::Impl::FollowRedirects(long max)
curl_easy_setopt(m_curl.get(), CURLOPT_MAXREDIRS, max);
}
const std::string HttpRequest::Impl::EscapeComponent(const std::string& string)
{
return curl_easy_escape(m_curl.get(), string.c_str(), static_cast<int>(string.size()));
}
static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata)
{
auto* buffer = static_cast<std::vector<u8>*>(userdata);

View File

@ -34,6 +34,7 @@ public:
void SetCookies(const std::string& cookies);
void UseIPv4();
void FollowRedirects(long max = 1);
const std::string EscapeComponent(const std::string& string);
Response Get(const std::string& url, const Headers& headers = {});
Response Post(const std::string& url, const std::vector<u8>& payload,
const Headers& headers = {});