add Http::allow_redirects(bool allow_redirects) method

This commit is contained in:
Tomasz Sowa 2022-08-13 20:00:15 +02:00
parent ca1a854fd1
commit e88615226b
2 changed files with 17 additions and 1 deletions

View File

@ -71,6 +71,7 @@ Http & Http::begin()
output_content_type = nullptr;
debug_mode = 0;
debug_info = nullptr;
follow_location = true;
return *this;
}
@ -407,6 +408,12 @@ void Http::add_bearer_token()
}
void Http::allow_redirects(bool allow_redirects)
{
this->follow_location = allow_redirects;
}
void Http::initialize_curl_if_needed()
@ -488,7 +495,7 @@ bool Http::fetch_internal(const char * url, const std::string * in, pt::TextStre
curl_easy_setopt(curl, CURLOPT_TIMEOUT, conn_timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, conn_timeout);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buf);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, (follow_location) ? 1 : 0);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 20);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

View File

@ -51,6 +51,8 @@ class Http : public WinixBase
public:
static const long HTTP_STATUS_200_OK = 200;
static const long HTTP_STATUS_301_Moved_Permanently = 301;
static const long HTTP_STATUS_302_Found = 302;
Http();
@ -143,6 +145,12 @@ public:
Http & add_bearer_token(const wchar_t * token);
Http & add_bearer_token(const std::wstring & token);
/*
* if allow_redirects is true then we follow any Location http headers
* default: true
*/
void allow_redirects(bool allow_redirects);
bool get(const wchar_t * url, std::wstring & out, bool clear_str = true);
bool get(const std::wstring & url, std::wstring & out, bool clear_str = true);
bool get(const pt::WTextStream & url, std::wstring & out, bool clear_str = true);
@ -180,6 +188,7 @@ private:
std::wstring * output_content_type;
long debug_mode;
pt::Space * debug_info;
bool follow_location;
std::wstring temp_header;
std::string temp_header_ascii;