-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathcreate_test_request.hpp
More file actions
149 lines (122 loc) · 4.03 KB
/
create_test_request.hpp
File metadata and controls
149 lines (122 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#if !defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION)
#error "Only <httpserver.hpp> or <httpserverpp> can be included directly."
#endif
#ifndef SRC_HTTPSERVER_CREATE_TEST_REQUEST_HPP_
#define SRC_HTTPSERVER_CREATE_TEST_REQUEST_HPP_
#include <map>
#include <string>
#include <vector>
#include "httpserver/http_request.hpp"
#include "httpserver/http_utils.hpp"
namespace httpserver {
class create_test_request {
public:
create_test_request() = default;
create_test_request& method(const std::string& method) {
_method = method;
return *this;
}
create_test_request& path(const std::string& path) {
_path = path;
return *this;
}
create_test_request& version(const std::string& version) {
_version = version;
return *this;
}
create_test_request& content(const std::string& content) {
_content = content;
return *this;
}
create_test_request& header(const std::string& key, const std::string& value) {
_headers[key] = value;
return *this;
}
create_test_request& footer(const std::string& key, const std::string& value) {
_footers[key] = value;
return *this;
}
create_test_request& cookie(const std::string& key, const std::string& value) {
_cookies[key] = value;
return *this;
}
create_test_request& arg(const std::string& key, const std::string& value) {
_args[key].push_back(value);
return *this;
}
create_test_request& querystring(const std::string& querystring) {
_querystring = querystring;
return *this;
}
#ifdef HAVE_BAUTH
create_test_request& user(const std::string& user) {
_user = user;
return *this;
}
create_test_request& pass(const std::string& pass) {
_pass = pass;
return *this;
}
#endif // HAVE_BAUTH
#ifdef HAVE_DAUTH
create_test_request& digested_user(const std::string& digested_user) {
_digested_user = digested_user;
return *this;
}
#endif // HAVE_DAUTH
create_test_request& requestor(const std::string& requestor) {
_requestor = requestor;
return *this;
}
create_test_request& requestor_port(uint16_t port) {
_requestor_port = port;
return *this;
}
#ifdef HAVE_GNUTLS
create_test_request& tls_enabled(bool enabled = true) {
_tls_enabled = enabled;
return *this;
}
#endif // HAVE_GNUTLS
http_request build();
private:
std::string _method = "GET";
std::string _path = "/";
std::string _version = "HTTP/1.1";
std::string _content;
http::header_map _headers;
http::header_map _footers;
http::header_map _cookies;
std::map<std::string, std::vector<std::string>, http::arg_comparator> _args;
std::string _querystring;
#ifdef HAVE_BAUTH
std::string _user;
std::string _pass;
#endif // HAVE_BAUTH
#ifdef HAVE_DAUTH
std::string _digested_user;
#endif // HAVE_DAUTH
std::string _requestor = "127.0.0.1";
uint16_t _requestor_port = 0;
#ifdef HAVE_GNUTLS
bool _tls_enabled = false;
#endif // HAVE_GNUTLS
};
} // namespace httpserver
#endif // SRC_HTTPSERVER_CREATE_TEST_REQUEST_HPP_