mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Improved Client2 interface
This commit is contained in:
parent
bbb83d12c1
commit
63a96aeb20
57
httplib.h
57
httplib.h
@ -5354,63 +5354,88 @@ public:
|
|||||||
|
|
||||||
void stop() { cli_->stop(); }
|
void stop() { cli_->stop(); }
|
||||||
|
|
||||||
void set_timeout_sec(time_t timeout_sec) {
|
Client2 &set_timeout_sec(time_t timeout_sec) {
|
||||||
cli_->set_timeout_sec(timeout_sec);
|
cli_->set_timeout_sec(timeout_sec);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_read_timeout(time_t sec, time_t usec) {
|
Client2 &set_read_timeout(time_t sec, time_t usec) {
|
||||||
cli_->set_read_timeout(sec, usec);
|
cli_->set_read_timeout(sec, usec);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_keep_alive_max_count(size_t count) {
|
Client2 &set_keep_alive_max_count(size_t count) {
|
||||||
cli_->set_keep_alive_max_count(count);
|
cli_->set_keep_alive_max_count(count);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_basic_auth(const char *username, const char *password) {
|
Client2 &set_basic_auth(const char *username, const char *password) {
|
||||||
cli_->set_basic_auth(username, password);
|
cli_->set_basic_auth(username, password);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void set_digest_auth(const char *username, const char *password) {
|
Client2 &set_digest_auth(const char *username, const char *password) {
|
||||||
cli_->set_digest_auth(username, password);
|
cli_->set_digest_auth(username, password);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set_follow_location(bool on) { cli_->set_follow_location(on); }
|
Client2 &set_follow_location(bool on) {
|
||||||
|
cli_->set_follow_location(on);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void set_compress(bool on) { cli_->set_compress(on); }
|
Client2 &set_compress(bool on) {
|
||||||
|
cli_->set_compress(on);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void set_interface(const char *intf) { cli_->set_interface(intf); }
|
Client2 &set_interface(const char *intf) {
|
||||||
|
cli_->set_interface(intf);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void set_proxy(const char *host, int port) { cli_->set_proxy(host, port); }
|
Client2 &set_proxy(const char *host, int port) {
|
||||||
|
cli_->set_proxy(host, port);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void set_proxy_basic_auth(const char *username, const char *password) {
|
Client2 &set_proxy_basic_auth(const char *username, const char *password) {
|
||||||
cli_->set_proxy_basic_auth(username, password);
|
cli_->set_proxy_basic_auth(username, password);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void set_proxy_digest_auth(const char *username, const char *password) {
|
Client2 &set_proxy_digest_auth(const char *username, const char *password) {
|
||||||
cli_->set_proxy_digest_auth(username, password);
|
cli_->set_proxy_digest_auth(username, password);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set_logger(Logger logger) { cli_->set_logger(logger); }
|
Client2 &set_logger(Logger logger) {
|
||||||
|
cli_->set_logger(logger);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// SSL
|
// SSL
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void set_ca_cert_path(const char *ca_cert_file_path,
|
Client2 &set_ca_cert_path(const char *ca_cert_file_path,
|
||||||
const char *ca_cert_dir_path = nullptr) {
|
const char *ca_cert_dir_path = nullptr) {
|
||||||
dynamic_cast<SSLClient &>(*cli_).set_ca_cert_path(ca_cert_file_path,
|
dynamic_cast<SSLClient &>(*cli_).set_ca_cert_path(ca_cert_file_path,
|
||||||
ca_cert_dir_path);
|
ca_cert_dir_path);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_ca_cert_store(X509_STORE *ca_cert_store) {
|
Client2 &set_ca_cert_store(X509_STORE *ca_cert_store) {
|
||||||
dynamic_cast<SSLClient &>(*cli_).set_ca_cert_store(ca_cert_store);
|
dynamic_cast<SSLClient &>(*cli_).set_ca_cert_store(ca_cert_store);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable_server_certificate_verification(bool enabled) {
|
Client2 &enable_server_certificate_verification(bool enabled) {
|
||||||
dynamic_cast<SSLClient &>(*cli_).enable_server_certificate_verification(
|
dynamic_cast<SSLClient &>(*cli_).enable_server_certificate_verification(
|
||||||
enabled);
|
enabled);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_openssl_verify_result() const {
|
long get_openssl_verify_result() const {
|
||||||
|
@ -674,10 +674,11 @@ TEST(HttpsToHttpRedirectTest, Redirect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(HttpsToHttpRedirectTest2, Redirect) {
|
TEST(HttpsToHttpRedirectTest2, Redirect) {
|
||||||
httplib::Client2 cli("https://httpbin.org");
|
|
||||||
cli.set_follow_location(true);
|
|
||||||
auto res =
|
auto res =
|
||||||
cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
httplib::Client2("https://httpbin.org")
|
||||||
|
.set_follow_location(true)
|
||||||
|
.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
||||||
|
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
EXPECT_EQ(200, res->status);
|
EXPECT_EQ(200, res->status);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user