lib/curl/Easy: add getter functions
This commit is contained in:
parent
7a473729af
commit
07be44a50a
@ -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:
|
|||||||
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()
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user