SNode.C
Loading...
Searching...
No Matches
web::http::client::Request Class Reference

#include <Request.h>

Inheritance diagram for web::http::client::Request:
Collaboration diagram for web::http::client::Request:

Public Member Functions

 Request (const std::string &connectionName, const std::string &host)
 Request (Request &)=delete
Requestoperator= (Request &)=delete
Requestoperator= (Request &&) noexcept=delete
std::string getConnectionName () const
Requesthost (const std::string &hostFieldValue)
Requestappend (const std::string &field, const std::string &value)
Requestset (const std::string &field, const std::string &value, bool overwrite=true)
Requestset (const std::map< std::string, std::string > &headers, bool overwrite=true)
Requesttype (const std::string &type)
Requestcookie (const std::string &name, const std::string &value)
Requestcookie (const std::map< std::string, std::string > &cookies)
Requestquery (const std::string &key, const std::string &value)
RequestsetTrailer (const std::string &field, const std::string &value, bool overwrite=true)
std::string header (const std::string &field) const
const std::map< std::string, std::string > & getQueries () const
const CiStringMap< std::string > & getHeaders () const
const CiStringMap< std::string > & getTrailer () const
const CiStringMap< std::string > & getCookies () const

Public Attributes

std::string hostFieldValue
std::string method = "GET"
std::string url = "/"
int httpMajor = 1
int httpMinor = 1
std::size_t count {0}

Protected Member Functions

 Request (Request &&request) noexcept

Protected Attributes

std::map< std::string, std::string > queries
CiStringMap< std::string > headers
CiStringMap< std::string > cookies
CiStringMap< std::string > trailer
std::string connectionName
std::size_t contentLength = 0
TransferEncoding transferEncoding = TransferEncoding::HTTP10
ConnectionState connectionState = ConnectionState::Default

Friends

class MasterRequest

Detailed Description

Definition at line 89 of file Request.h.

Constructor & Destructor Documentation

◆ Request() [1/3]

web::http::client::Request::Request ( const std::string & connectionName,
const std::string & host )

Definition at line 77 of file Request.cpp.

81 set("X-Powered-By", "SNode.C");
82 }
Request & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:143
std::string connectionName
Definition Request.h:134
std::string hostFieldValue
Definition Request.h:120
Request & host(const std::string &hostFieldValue)
Definition Request.cpp:125

References connectionName, host(), hostFieldValue, and set().

Referenced by web::http::client::MasterRequest::MasterRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Request() [2/3]

web::http::client::Request::Request ( Request & )
explicitdelete

◆ Request() [3/3]

web::http::client::Request::Request ( Request && request)
explicitprotectednoexcept

Definition at line 84 of file Request.cpp.

85 : hostFieldValue(request.hostFieldValue) // NOLINT
86 , method(std::move(request.method))
87 , url(std::move(request.url))
88 , httpMajor(request.httpMajor)
89 , httpMinor(request.httpMinor)
90 , count(request.count)
91 , queries(std::move(request.queries))
92 , headers(std::move(request.headers))
93 , cookies(std::move(request.cookies))
94 , trailer(std::move(request.trailer))
95 , connectionName(request.connectionName)
96 , contentLength(request.contentLength)
97 , transferEncoding(request.transferEncoding)
98 , connectionState(request.connectionState) {
99 request.count++;
100
102 set("X-Powered-By", "SNode.C");
103 }
CiStringMap< std::string > headers
Definition Request.h:130
std::map< std::string, std::string > queries
Definition Request.h:129
TransferEncoding transferEncoding
Definition Request.h:138
ConnectionState connectionState
Definition Request.h:139
CiStringMap< std::string > cookies
Definition Request.h:131
CiStringMap< std::string > trailer
Definition Request.h:132
std::size_t contentLength
Definition Request.h:136

References connectionName, connectionState, contentLength, cookies, count, headers, host(), hostFieldValue, httpMajor, httpMinor, method, queries, set(), trailer, transferEncoding, and url.

Referenced by web::http::client::MasterRequest::MasterRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ append()

Request & web::http::client::Request::append ( const std::string & field,
const std::string & value )

Definition at line 131 of file Request.cpp.

131 {
132 const std::map<std::string, std::string>::iterator it = headers.find(field);
133
134 if (it != headers.end()) {
135 set(field, it->second.append(", ").append(value));
136 } else {
137 set(field, value);
138 }
139
140 return *this;
141 }

References headers, and set().

Here is the call graph for this function:

◆ cookie() [1/2]

Request & web::http::client::Request::cookie ( const std::map< std::string, std::string > & cookies)

Definition at line 209 of file Request.cpp.

209 {
210 for (const auto& [name, value] : cookies) {
211 cookie(name, value);
212 }
213
214 return *this;
215 }
Request & cookie(const std::string &name, const std::string &value)
Definition Request.cpp:203

References cookie().

Here is the call graph for this function:

◆ cookie() [2/2]

Request & web::http::client::Request::cookie ( const std::string & name,
const std::string & value )

Definition at line 203 of file Request.cpp.

203 {
204 cookies.insert({name, value});
205
206 return *this;
207 }

References cookies.

Referenced by cookie().

Here is the caller graph for this function:

◆ getConnectionName()

std::string web::http::client::Request::getConnectionName ( ) const

Definition at line 105 of file Request.cpp.

105 {
106 return connectionName;
107 }

References connectionName.

Referenced by main().

Here is the caller graph for this function:

◆ getCookies()

const CiStringMap< std::string > & web::http::client::Request::getCookies ( ) const

Definition at line 260 of file Request.cpp.

260 {
261 return cookies;
262 }

References cookies.

Referenced by web::http::client::SocketContext::requestPrepared().

Here is the caller graph for this function:

◆ getHeaders()

const CiStringMap< std::string > & web::http::client::Request::getHeaders ( ) const

Definition at line 252 of file Request.cpp.

252 {
253 return headers;
254 }

References headers.

Referenced by web::http::client::SocketContext::requestPrepared().

Here is the caller graph for this function:

◆ getQueries()

const std::map< std::string, std::string > & web::http::client::Request::getQueries ( ) const

Definition at line 248 of file Request.cpp.

248 {
249 return queries;
250 }

References queries.

Referenced by web::http::client::SocketContext::requestPrepared().

Here is the caller graph for this function:

◆ getTrailer()

const CiStringMap< std::string > & web::http::client::Request::getTrailer ( ) const

Definition at line 256 of file Request.cpp.

256 {
257 return trailer;
258 }

References trailer.

Referenced by web::http::client::SocketContext::requestPrepared().

Here is the caller graph for this function:

◆ header()

std::string web::http::client::Request::header ( const std::string & field) const

Definition at line 242 of file Request.cpp.

242 {
243 auto fieldElement = headers.find(field);
244
245 return fieldElement != headers.end() ? fieldElement->second : "";
246 }

References headers.

Referenced by web::websocket::client::SocketContextUpgradeFactory::create(), main(), web::http::client::MasterRequest::requestEventSource(), web::http::client::SocketContext::requestPrepared(), and web::http::client::MasterRequest::upgrade().

Here is the caller graph for this function:

◆ host()

Request & web::http::client::Request::host ( const std::string & hostFieldValue)

Definition at line 125 of file Request.cpp.

125 {
126 set("Host", hostFieldValue, true);
127
128 return *this;
129 }

References set().

Referenced by Request(), and Request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

Request & web::http::client::Request::operator= ( Request && )
deletenoexcept

◆ operator=() [2/2]

Request & web::http::client::Request::operator= ( Request & )
delete

◆ query()

Request & web::http::client::Request::query ( const std::string & key,
const std::string & value )

Definition at line 217 of file Request.cpp.

217 {
218 queries.insert({key, value});
219
220 return *this;
221 }

References queries.

◆ set() [1/2]

Request & web::http::client::Request::set ( const std::map< std::string, std::string > & headers,
bool overwrite = true )

Definition at line 189 of file Request.cpp.

189 {
190 for (const auto& [field, value] : headers) {
191 set(field, value, overwrite);
192 }
193
194 return *this;
195 }

References set().

Here is the call graph for this function:

◆ set() [2/2]

Request & web::http::client::Request::set ( const std::string & field,
const std::string & value,
bool overwrite = true )

Definition at line 143 of file Request.cpp.

143 {
144 if (!value.empty()) {
145 if (overwrite) {
146 headers.insert_or_assign(field, value);
147 } else {
148 headers.insert({field, value});
149 }
150
151 if (web::http::ciEquals(field, "Connection")) {
152 if (web::http::ciContains(headers[field], "close")) {
154 } else if (web::http::ciContains(headers[field], "keep-alive")) {
156 }
157 } else if (web::http::ciEquals(field, "Content-Length")) {
158 contentLength = std::stoul(value);
160 headers.erase("Transfer-Encoding");
161 } else if (web::http::ciEquals(field, "Transfer-Encoding")) {
162 if (web::http::ciContains(headers[field], "chunked")) {
164 headers.erase("Content-Length");
165 }
166 if (web::http::ciContains(headers[field], "compressed")) {
167 }
168 if (web::http::ciContains(headers[field], "deflate")) {
169 }
170 if (web::http::ciContains(headers[field], "gzip")) {
171 }
172 } else if (web::http::ciEquals(field, "Content-Encoding")) {
173 if (web::http::ciContains(headers[field], "compressed")) {
174 }
175 if (web::http::ciContains(headers[field], "deflate")) {
176 }
177 if (web::http::ciContains(headers[field], "gzip")) {
178 }
179 if (web::http::ciContains(headers[field], "br")) {
180 }
181 }
182 } else {
183 headers.erase(field);
184 }
185
186 return *this;
187 }
bool ciEquals(const std::string &str1, const std::string &str2)
bool ciContains(const std::string &str1, const std::string &str2)

References web::http::Chunked, web::http::ciContains(), web::http::ciEquals(), web::http::Close, connectionState, contentLength, headers, web::http::Identity, web::http::Keep, and transferEncoding.

Referenced by append(), NextTester::dispatchNextRequest(), web::http::client::MasterRequest::executeSendFile(), web::http::client::MasterRequest::executeSendHeader(), web::http::client::MasterRequest::executeUpgrade(), host(), main(), web::websocket::client::SocketContextUpgradeFactory::prepare(), Request(), Request(), web::http::client::MasterRequest::requestEventSource(), web::http::client::MasterRequest::send(), web::http::client::MasterRequest::send(), set(), and setTrailer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTrailer()

Request & web::http::client::Request::setTrailer ( const std::string & field,
const std::string & value,
bool overwrite = true )

Definition at line 223 of file Request.cpp.

223 {
224 if (!value.empty()) {
225 if (overwrite) {
226 trailer.insert_or_assign(field, value);
227 } else {
228 trailer.insert({field, value});
229 }
230 if (!headers.contains("Trailer")) {
231 set("Trailer", field);
232 } else {
233 headers["Trailer"].append("," + field);
234 }
235 } else {
236 trailer.erase(field);
237 }
238
239 return *this;
240 }

References headers, set(), and trailer.

Here is the call graph for this function:

◆ type()

Request & web::http::client::Request::type ( const std::string & type)

Definition at line 197 of file Request.cpp.

197 {
198 headers.insert({"Content-Type", type});
199
200 return *this;
201 }
Request & type(const std::string &type)
Definition Request.cpp:197

References headers.

Referenced by main().

Here is the caller graph for this function:

◆ MasterRequest

friend class MasterRequest
friend

Definition at line 141 of file Request.h.

Member Data Documentation

◆ connectionName

std::string web::http::client::Request::connectionName
protected

◆ connectionState

ConnectionState web::http::client::Request::connectionState = ConnectionState::Default
protected

Definition at line 139 of file Request.h.

Referenced by web::http::client::MasterRequest::init(), Request(), and set().

◆ contentLength

◆ cookies

◆ count

◆ headers

◆ hostFieldValue

std::string web::http::client::Request::hostFieldValue

Definition at line 120 of file Request.h.

Referenced by Request(), and Request().

◆ httpMajor

◆ httpMinor

◆ method

◆ queries

std::map<std::string, std::string> web::http::client::Request::queries
protected

◆ trailer

◆ transferEncoding

◆ url


The documentation for this class was generated from the following files: