Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 93e811d

Browse files
committed
added header parameter to Client::request
1 parent 6714b15 commit 93e811d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

client_http.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <boost/asio.hpp>
55

66
#include <unordered_map>
7+
#include <map>
78
#include <iostream>
89
#include <regex>
910
#include <random>
@@ -29,12 +30,14 @@ namespace SimpleWeb {
2930
};
3031

3132
//TODO add header parameters
32-
std::shared_ptr<Response> request(const std::string& request_type, const std::string& path="/") {
33+
std::shared_ptr<Response> request(const std::string& request_type, const std::string& path="/",
34+
const std::map<std::string, std::string>& header={{}}) {
3335
std::stringstream empty_ss;
34-
return request(request_type, path, empty_ss);
36+
return request(request_type, path, empty_ss, header);
3537
}
3638

37-
std::shared_ptr<Response> request(const std::string& request_type, const std::string& path, std::ostream& content) {
39+
std::shared_ptr<Response> request(const std::string& request_type, const std::string& path, std::ostream& content,
40+
const std::map<std::string, std::string>& header={{}}) {
3841
std::string corrected_path=path;
3942
if(corrected_path=="")
4043
corrected_path="/";
@@ -47,6 +50,9 @@ namespace SimpleWeb {
4750
std::ostream write_stream(&write_buffer);
4851
write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n";
4952
write_stream << "Host: " << host << "\r\n";
53+
for(auto& h: header) {
54+
write_stream << h.first << ": " << h.second << "\r\n";
55+
}
5056
if(content_length>0)
5157
write_stream << "Content-Length: " << std::to_string(content_length) << "\r\n";
5258
write_stream << "\r\n";

0 commit comments

Comments
 (0)