From 93e811d6498d77569fe673c40fefd2a157af1b5a Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 13 Aug 2014 09:53:35 +0200 Subject: [PATCH] added header parameter to Client::request --- client_http.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index d221a66..305a79e 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -29,12 +30,14 @@ namespace SimpleWeb { }; //TODO add header parameters - std::shared_ptr request(const std::string& request_type, const std::string& path="/") { + std::shared_ptr request(const std::string& request_type, const std::string& path="/", + const std::map& header={{}}) { std::stringstream empty_ss; - return request(request_type, path, empty_ss); + return request(request_type, path, empty_ss, header); } - std::shared_ptr request(const std::string& request_type, const std::string& path, std::ostream& content) { + std::shared_ptr request(const std::string& request_type, const std::string& path, std::ostream& content, + const std::map& header={{}}) { std::string corrected_path=path; if(corrected_path=="") corrected_path="/"; @@ -47,6 +50,9 @@ namespace SimpleWeb { std::ostream write_stream(&write_buffer); write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n"; write_stream << "Host: " << host << "\r\n"; + for(auto& h: header) { + write_stream << h.first << ": " << h.second << "\r\n"; + } if(content_length>0) write_stream << "Content-Length: " << std::to_string(content_length) << "\r\n"; write_stream << "\r\n";