-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathcreate_test_request.hpp
More file actions
165 lines (137 loc) · 5.33 KB
/
Copy pathcreate_test_request.hpp
File metadata and controls
165 lines (137 loc) · 5.33 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
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;
}
// TASK-034: setters are unconditional. On HAVE_BAUTH-off /
// HAVE_DAUTH-off builds the values are silently dropped on .build()
// (matching the sentinel-empty contract of the corresponding
// http_request accessors).
create_test_request& user(const std::string& user) {
_user = user;
return *this;
}
create_test_request& pass(const std::string& pass) {
_pass = pass;
return *this;
}
create_test_request& digested_user(const std::string& digested_user) {
_digested_user = digested_user;
return *this;
}
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;
}
// TASK-034: setter is unconditional. On HAVE_GNUTLS-off builds the
// value is silently dropped (has_tls_session() returns false
// regardless — TASK-019 sentinel contract).
create_test_request& tls_enabled(bool enabled = true) {
_tls_enabled = enabled;
return *this;
}
// TASK-057: opt out of the default credential-redaction policy in
// http_request::operator<<. Mirrors the webserver-side builder
// setter @ref create_webserver::expose_credentials_in_logs for the
// unit-test scope (no webserver construction). The no-argument form
// (`expose_credentials_in_logs()`) is shorthand for `enable=true`
// and must not appear outside test scope — it reinforces the
// development-only intent without forcing callers to type the
// boolean argument.
create_test_request& expose_credentials_in_logs(bool enable = true) {
_expose_credentials_in_logs = enable;
return *this;
}
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;
// TASK-034: fields stored unconditionally. On HAVE_*-off builds the
// values are populated by the setters but silently dropped during
// .build() propagation, matching the sentinel-empty contract on
// the http_request accessor side.
std::string _user;
std::string _pass;
std::string _digested_user;
std::string _requestor = "127.0.0.1";
uint16_t _requestor_port = 0;
bool _tls_enabled = false;
// TASK-057: default false (secure-by-default). When true, build()
// sets http_request_impl::expose_credentials_in_logs_ so the
// diagnostic dump streams the v1 verbose form.
bool _expose_credentials_in_logs = false;
};
} // namespace httpserver
#endif // SRC_HTTPSERVER_CREATE_TEST_REQUEST_HPP_