4
4
#include < boost/asio.hpp>
5
5
6
6
#include < unordered_map>
7
+ #include < map>
7
8
#include < iostream>
8
9
#include < regex>
9
10
#include < random>
@@ -29,12 +30,14 @@ namespace SimpleWeb {
29
30
};
30
31
31
32
// 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={{}}) {
33
35
std::stringstream empty_ss;
34
- return request (request_type, path, empty_ss);
36
+ return request (request_type, path, empty_ss, header );
35
37
}
36
38
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={{}}) {
38
41
std::string corrected_path=path;
39
42
if (corrected_path==" " )
40
43
corrected_path=" /" ;
@@ -47,6 +50,9 @@ namespace SimpleWeb {
47
50
std::ostream write_stream (&write_buffer);
48
51
write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n " ;
49
52
write_stream << " Host: " << host << " \r\n " ;
53
+ for (auto & h: header) {
54
+ write_stream << h.first << " : " << h.second << " \r\n " ;
55
+ }
50
56
if (content_length>0 )
51
57
write_stream << " Content-Length: " << std::to_string (content_length) << " \r\n " ;
52
58
write_stream << " \r\n " ;
0 commit comments