This commit is contained in:
yhirose 2017-06-28 20:12:11 -04:00
parent 6d01712fc7
commit ddb454da1b

View file

@ -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<Response> Client::get(const char* path)
{
Request req;
req.method = "GET";
req.path = path;
add_default_headers(req);
auto res = std::make_shared<Response>();
@ -1094,6 +1103,7 @@ inline std::shared_ptr<Response> Client::head(const char* path)
Request req;
req.method = "HEAD";
req.path = path;
add_default_headers(req);
auto res = std::make_shared<Response>();
@ -1106,6 +1116,8 @@ inline std::shared_ptr<Response> Client::post(
Request req;
req.method = "POST";
req.path = path;
add_default_headers(req);
req.set_header("Content-Type", content_type);
req.body = body;