From ddb454da1b4fef4f86867b95e339eab52c782b3a Mon Sep 17 00:00:00 2001 From: yhirose Date: Wed, 28 Jun 2017 20:12:11 -0400 Subject: [PATCH] Fixed #7 --- httplib.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/httplib.h b/httplib.h index 014306d..69b3d42 100644 --- a/httplib.h +++ b/httplib.h @@ -176,6 +176,7 @@ protected: private: bool read_response_line(Stream& strm, Response& res); + void add_default_headers(Request& req); virtual bool read_and_close_socket(socket_t sock, const Request& req, Response& res); @@ -1078,11 +1079,19 @@ inline bool Client::read_and_close_socket(socket_t sock, const Request& req, Res }); } +inline void Client::add_default_headers(Request& req) +{ + req.set_header("Host", host_.c_str()); + req.set_header("Accept", "*/*"); + req.set_header("User-Agent", "cpp-httplib/0.1"); +} + inline std::shared_ptr Client::get(const char* path) { Request req; req.method = "GET"; req.path = path; + add_default_headers(req); auto res = std::make_shared(); @@ -1094,6 +1103,7 @@ inline std::shared_ptr Client::head(const char* path) Request req; req.method = "HEAD"; req.path = path; + add_default_headers(req); auto res = std::make_shared(); @@ -1106,6 +1116,8 @@ inline std::shared_ptr Client::post( Request req; req.method = "POST"; req.path = path; + add_default_headers(req); + req.set_header("Content-Type", content_type); req.body = body;