mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fixed #7
This commit is contained in:
parent
6d01712fc7
commit
ddb454da1b
1 changed files with 12 additions and 0 deletions
12
httplib.h
12
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<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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue