Commit 07be44a5 authored by Max Kellermann's avatar Max Kellermann

lib/curl/Easy: add getter functions

parent 7a473729
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#ifndef CURL_EASY_HXX #ifndef CURL_EASY_HXX
#define CURL_EASY_HXX #define CURL_EASY_HXX
#include "util/Compiler.h"
#include <curl/curl.h> #include <curl/curl.h>
#include <utility> #include <utility>
...@@ -160,6 +162,22 @@ public: ...@@ -160,6 +162,22 @@ public:
SetOption(CURLOPT_HTTPPOST, post); SetOption(CURLOPT_HTTPPOST, post);
} }
template<typename T>
bool GetInfo(CURLINFO info, T value_r) const noexcept {
return ::curl_easy_getinfo(handle, info, value_r) == CURLE_OK;
}
/**
* Returns the response body's size, or -1 if that is unknown.
*/
gcc_pure
int64_t GetContentLength() const noexcept {
double value;
return GetInfo(CURLINFO_CONTENT_LENGTH_DOWNLOAD, &value)
? (int64_t)value
: -1;
}
bool Unpause() noexcept { bool Unpause() noexcept {
return ::curl_easy_pause(handle, CURLPAUSE_CONT) == CURLE_OK; return ::curl_easy_pause(handle, CURLPAUSE_CONT) == CURLE_OK;
} }
......
...@@ -140,7 +140,7 @@ CurlRequest::FinishHeaders() ...@@ -140,7 +140,7 @@ CurlRequest::FinishHeaders()
state = State::BODY; state = State::BODY;
long status = 0; long status = 0;
curl_easy_getinfo(easy.Get(), CURLINFO_RESPONSE_CODE, &status); easy.GetInfo(CURLINFO_RESPONSE_CODE, &status);
handler.OnHeaders(status, std::move(headers)); handler.OnHeaders(status, std::move(headers));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment