SNode.C
Loading...
Searching...
No Matches
web::http::server::Response Class Reference

#include <Response.h>

Inheritance diagram for web::http::server::Response:
Collaboration diagram for web::http::server::Response:

Public Member Functions

 Response (SocketContext *socketContext)
 
 Response (Response &)=delete
 
 Response (Response &&) noexcept=delete
 
Responseoperator= (Response &)=delete
 
Responseoperator= (Response &&) noexcept=delete
 
 ~Response () override
 
void disconnect ()
 
bool isConnected () const
 
Responsestatus (int statusCode)
 
Responseappend (const std::string &field, const std::string &value)
 
Responseset (const std::string &field, const std::string &value, bool overwrite=true)
 
Responseset (const std::map< std::string, std::string > &headers, bool overwrite=true)
 
Responsetype (const std::string &type)
 
Responsecookie (const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
 
ResponseclearCookie (const std::string &name, const std::map< std::string, std::string > &options={})
 
ResponsesetTrailer (const std::string &field, const std::string &value, bool overwrite=true)
 
void send (const char *chunk, std::size_t chunkLen)
 
void send (const std::string &chunk)
 
void sendStatus (int statusCode)
 
void upgrade (const std::shared_ptr< Request > &request, const std::function< void(const std::string &)> &status)
 
void sendFile (const std::string &file, const std::function< void(int)> &callback)
 
void end ()
 
ResponsesendHeader ()
 
ResponsesendFragment (const char *chunk, std::size_t chunkLen)
 
ResponsesendFragment (const std::string &chunk)
 
const std::string & header (const std::string &field)
 
SocketContextgetSocketContext () const
 
- Public Member Functions inherited from core::pipe::Sink
 Sink (Sink &)=delete
 
Sinkoperator= (Sink &)=delete
 

Public Attributes

std::string requestMethod = "GET"
 
int statusCode = 200
 
int httpMajor = 1
 
int httpMinor = 1
 

Protected Attributes

web::http::CiStringMap< std::string > headers
 
web::http::CiStringMap< web::http::CookieOptionscookies
 
web::http::CiStringMap< std::string > trailer
 

Private Member Functions

virtual void init ()
 
void sendCompleted ()
 
void onSourceConnect (core::pipe::Source *source) override
 
void onSourceData (const char *chunk, std::size_t chunkLen) override
 
void onSourceEof () override
 
void onSourceError (int errnum) override
 

Private Attributes

std::size_t contentSent = 0
 
std::size_t contentLength = 0
 
web::http::server::SocketContextsocketContext = nullptr
 
ConnectionState connectionState = ConnectionState::Default
 
TransferEncoding transferEncoding = TransferEncoding::HTTP10
 

Friends

class SocketContext
 

Additional Inherited Members

- Protected Member Functions inherited from core::pipe::Sink
 Sink ()=default
 
 Sink (Sink &&) noexcept=default
 
Sinkoperator= (Sink &&) noexcept=default
 
virtual ~Sink ()
 
bool isStreaming ()
 
void stop ()
 

Detailed Description

Definition at line 69 of file Response.h.

Constructor & Destructor Documentation

◆ Response() [1/3]

web::http::server::Response::Response ( SocketContext socketContext)
explicit

Definition at line 72 of file Response.cpp.

74 }
web::http::server::SocketContext * socketContext
Definition Response.h:135

References socketContext.

◆ Response() [2/3]

web::http::server::Response::Response ( Response )
explicitdelete

◆ Response() [3/3]

web::http::server::Response::Response ( Response &&  )
explicitdeletenoexcept

◆ ~Response()

web::http::server::Response::~Response ( )
override

Definition at line 76 of file Response.cpp.

76 {
77 if (isConnected() && Sink::isStreaming()) {
79 }
80 }

References isConnected(), core::pipe::Sink::isStreaming(), socketContext, and core::socket::stream::SocketContext::streamEof().

Here is the call graph for this function:

Member Function Documentation

◆ append()

Response & web::http::server::Response::append ( const std::string &  field,
const std::string &  value 
)

Definition at line 110 of file Response.cpp.

110 {
111 const std::map<std::string, std::string>::iterator it = headers.find(field);
112
113 if (it != headers.end()) {
114 set(field, it->second.append(", ").append(value));
115 } else {
116 set(field, value);
117 }
118
119 return *this;
120 }
web::http::CiStringMap< std::string > headers
Definition Response.h:127
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:130

References headers, and set().

Referenced by express::Response::append().

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

◆ clearCookie()

Response & web::http::server::Response::clearCookie ( const std::string &  name,
const std::map< std::string, std::string > &  options = {} 
)

Definition at line 186 of file Response.cpp.

186 {
187 std::map<std::string, std::string> opts = options;
188
189 opts.erase("Max-Age");
190 const time_t time = 0;
191 opts["Expires"] = httputils::to_http_date(utils::system::gmtime(&time));
192
193 return cookie(name, "", opts);
194 }
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
Definition Response.cpp:180
std::string to_http_date(struct tm *tm)
struct tm * gmtime(const time_t *timep)
Definition time.cpp:62
time_t time(time_t *tloc)
Definition time.cpp:52

References cookie(), utils::system::gmtime(), and httputils::to_http_date().

Referenced by express::Response::clearCookie().

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

◆ cookie()

Response & web::http::server::Response::cookie ( const std::string &  name,
const std::string &  value,
const std::map< std::string, std::string > &  options = {} 
)

Definition at line 180 of file Response.cpp.

180 {
181 cookies.insert({name, CookieOptions(value, options)});
182
183 return *this;
184 }
web::http::CiStringMap< web::http::CookieOptions > cookies
Definition Response.h:128

References web::http::CookieOptions::CookieOptions(), and cookies.

Referenced by clearCookie(), and express::Response::cookie().

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

◆ disconnect()

void web::http::server::Response::disconnect ( )

Definition at line 82 of file Response.cpp.

82 {
83 stop();
84 socketContext = nullptr;
85 }
void stop()
Definition Sink.cpp:69

References socketContext, and core::pipe::Sink::stop().

Referenced by web::http::server::SocketContext::onDisconnected().

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

◆ end()

void web::http::server::Response::end ( )

Definition at line 363 of file Response.cpp.

363 {
364 send("");
365 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:215

References send().

Referenced by express::Response::end().

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

◆ getSocketContext()

SocketContext * web::http::server::Response::getSocketContext ( ) const

Definition at line 485 of file Response.cpp.

485 {
486 return socketContext;
487 }

References socketContext.

Referenced by express::Response::getSocketContext().

Here is the caller graph for this function:

◆ header()

const std::string & web::http::server::Response::header ( const std::string &  field)

Definition at line 481 of file Response.cpp.

481 {
482 return headers[field];
483 }

References headers.

Referenced by express::Response::header(), and upgrade().

Here is the caller graph for this function:

◆ init()

void web::http::server::Response::init ( )
privatevirtual

Definition at line 91 of file Response.cpp.

References connectionState, contentLength, contentSent, cookies, web::http::Default, headers, web::http::HTTP10, httpMajor, httpMinor, statusCode, trailer, and transferEncoding.

Referenced by web::http::server::SocketContext::deliverRequest().

Here is the caller graph for this function:

◆ isConnected()

bool web::http::server::Response::isConnected ( ) const

Definition at line 87 of file Response.cpp.

87 {
88 return socketContext != nullptr;
89 }

References socketContext.

Referenced by express::Response::isConnected(), onSourceConnect(), onSourceEof(), onSourceError(), send(), sendCompleted(), sendFile(), sendFragment(), sendHeader(), upgrade(), and ~Response().

Here is the caller graph for this function:

◆ onSourceConnect()

void web::http::server::Response::onSourceConnect ( core::pipe::Source source)
overrideprivatevirtual

Implements core::pipe::Sink.

Definition at line 444 of file Response.cpp.

444 {
445 if (isConnected()) {
447 sendHeader();
448
449 source->start();
450 } else {
451 source->stop();
452 }
453 } else {
454 source->stop();
455 }
456 }
Source * source
Definition Sink.h:90
virtual void stop()=0
virtual void start()=0
bool streamToPeer(core::pipe::Source *source) const

References isConnected(), sendHeader(), socketContext, core::pipe::Source::start(), core::pipe::Source::stop(), and core::socket::stream::SocketContext::streamToPeer().

Here is the call graph for this function:

◆ onSourceData()

void web::http::server::Response::onSourceData ( const char *  chunk,
std::size_t  chunkLen 
)
overrideprivatevirtual

Implements core::pipe::Sink.

Definition at line 458 of file Response.cpp.

458 {
459 sendFragment(chunk, chunkLen);
460 }
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:404

References sendFragment().

Here is the call graph for this function:

◆ onSourceEof()

void web::http::server::Response::onSourceEof ( )
overrideprivatevirtual

Implements core::pipe::Sink.

Definition at line 462 of file Response.cpp.

462 {
463 if (isConnected()) {
465 }
466
468 }

References isConnected(), sendCompleted(), socketContext, and core::socket::stream::SocketContext::streamEof().

Here is the call graph for this function:

◆ onSourceError()

void web::http::server::Response::onSourceError ( int  errnum)
overrideprivatevirtual

Implements core::pipe::Sink.

Definition at line 470 of file Response.cpp.

470 {
471 errno = errnum;
472
473 if (isConnected()) {
476 }
477
479 }

References core::socket::stream::SocketContext::close(), isConnected(), sendCompleted(), socketContext, and core::socket::stream::SocketContext::streamEof().

Here is the call graph for this function:

◆ operator=() [1/2]

Response & web::http::server::Response::operator= ( Response &&  )
deletenoexcept

◆ operator=() [2/2]

Response & web::http::server::Response::operator= ( Response )
delete

◆ send() [1/2]

void web::http::server::Response::send ( const char *  chunk,
std::size_t  chunkLen 
)

Definition at line 215 of file Response.cpp.

215 {
216 if (isConnected()) {
217 if (chunkLen > 0) {
218 set("Content-Type", "application/octet-stream", false);
219 }
220 set("Content-Length", std::to_string(chunkLen));
221
222 sendHeader();
223 sendFragment(chunk, chunkLen);
225 }
226 }

References isConnected(), sendCompleted(), sendFragment(), sendHeader(), and set().

Referenced by express::Response::send(), and send().

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

◆ send() [2/2]

void web::http::server::Response::send ( const std::string &  chunk)

Definition at line 228 of file Response.cpp.

228 {
229 if (!chunk.empty()) {
230 set("Content-Type", "text/html; charset=utf-8", false);
231 }
232
233 send(chunk.data(), chunk.size());
234 }

References send(), and set().

Referenced by web::http::server::SocketContext::deliverRequest(), end(), express::Response::send(), and sendStatus().

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

◆ sendCompleted()

void web::http::server::Response::sendCompleted ( )
private

Definition at line 426 of file Response.cpp.

426 {
427 if (isConnected()) {
429 sendFragment(""); // For transfer encoding chunked. Terminate the chunk sequence.
430
431 if (!trailer.empty()) {
432 for (auto& [field, value] : trailer) {
433 socketContext->sendToPeer(std::string(field).append(":").append(value).append("\r\n"));
434 }
435
436 socketContext->sendToPeer("\r\n");
437 }
438 }
439
441 }
442 }
void sendToPeer(const char *chunk, std::size_t chunkLen) const final
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:110
void responseCompleted(const Response &response, bool success)

References web::http::Chunked, contentLength, contentSent, httpMajor, httpMinor, isConnected(), web::http::server::SocketContext::responseCompleted(), sendFragment(), core::socket::SocketContext::sendToPeer(), socketContext, trailer, and transferEncoding.

Referenced by onSourceEof(), onSourceError(), and send().

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

◆ sendFile()

void web::http::server::Response::sendFile ( const std::string &  file,
const std::function< void(int)> &  callback 
)

Definition at line 324 of file Response.cpp.

324 {
325 if (isConnected()) {
326 std::string absolutFileName = file;
327
328 if (std::filesystem::exists(absolutFileName)) {
329 std::error_code ec;
330 absolutFileName = std::filesystem::canonical(absolutFileName);
331
332 if (std::filesystem::is_regular_file(absolutFileName, ec) && !ec) {
333 core::file::FileReader::open(absolutFileName, [this, &absolutFileName, &onStatus](int fd) {
334 onStatus(errno);
335
336 if (fd >= 0) {
337 set("Content-Type", web::http::MimeTypes::contentType(absolutFileName), false);
338 set("Last-Modified", httputils::file_mod_http_date(absolutFileName), false);
339 if (httpMajor == 1) {
340 if (httpMinor == 1) {
341 set("Transfer-Encoding", "chunked");
342 } else {
343 set("Content-Length", std::to_string(std::filesystem::file_size(absolutFileName)));
344 }
345 }
346 } else {
347 status(404);
348 }
349 })->pipe(this);
350 } else {
351 status(404);
352 errno = EEXIST;
353 onStatus(errno);
354 }
355 } else {
356 status(404);
357 errno = ENOENT;
358 onStatus(errno);
359 }
360 }
361 }
static FileReader * open(const std::string &path, const std::function< void(int)> &callback)
void pipe(Source *source)
Definition Sink.cpp:58
static std::string contentType(const std::string &file)
Response & status(int statusCode)
Definition Response.cpp:104
std::string file_mod_http_date(const std::string &filePath)

References web::http::MimeTypes::contentType(), httputils::file_mod_http_date(), httpMajor, httpMinor, isConnected(), core::file::FileReader::open(), core::pipe::Source::pipe(), set(), and status().

Referenced by express::Response::sendFile().

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

◆ sendFragment() [1/2]

Response & web::http::server::Response::sendFragment ( const char *  chunk,
std::size_t  chunkLen 
)

Definition at line 404 of file Response.cpp.

404 {
405 if (isConnected()) {
407 socketContext->sendToPeer(to_hex_str(chunkLen).append("\r\n"));
408 }
409
410 socketContext->sendToPeer(chunk, chunkLen);
411 contentSent += chunkLen;
412
413 if (transferEncoding == TransferEncoding::Chunked || web::http::ciContains(headers["Content-Type"], "text/event-stream")) {
414 socketContext->sendToPeer("\r\n");
415 contentLength += chunkLen;
416 }
417 }
418
419 return *this;
420 }
bool ciContains(const std::string &str1, const std::string &str2)
#define to_hex_str(int_val)
Definition Request.cpp:73

References web::http::Chunked, web::http::ciContains(), contentLength, contentSent, headers, isConnected(), core::socket::stream::SocketContext::sendToPeer(), core::socket::SocketContext::sendToPeer(), socketContext, and transferEncoding.

Referenced by onSourceData(), send(), express::Response::sendFragment(), and sendFragment().

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

◆ sendFragment() [2/2]

Response & web::http::server::Response::sendFragment ( const std::string &  chunk)

Definition at line 422 of file Response.cpp.

422 {
423 return sendFragment(chunk.data(), chunk.size());
424 }

References sendFragment().

Referenced by sendCompleted(), and express::Response::sendFragment().

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

◆ sendHeader()

Response & web::http::server::Response::sendHeader ( )

Definition at line 367 of file Response.cpp.

367 {
368 if (isConnected()) {
370
371 socketContext->sendToPeer("HTTP/" + std::to_string(httpMajor)
372 .append(".")
373 .append(std::to_string(httpMinor))
374 .append(" ")
375 .append(std::to_string(statusCode))
376 .append(" ")
378 .append("\r\n"));
379 socketContext->sendToPeer("Date: " + httputils::to_http_date() + "\r\n");
380
381 set("X-Powered-By", "snode.c");
382
383 for (const auto& [field, value] : headers) {
384 socketContext->sendToPeer(std::string(field).append(": ").append(value).append("\r\n"));
385 }
386
387 for (const auto& [cookie, cookieValue] : cookies) {
388 const std::string cookieString = std::accumulate(
389 cookieValue.getOptions().begin(),
390 cookieValue.getOptions().end(),
391 cookie + "=" + cookieValue.getValue(),
392 [](const std::string& str, const std::pair<const std::string&, const std::string&> option) -> std::string {
393 return str + "; " + option.first + (!option.second.empty() ? "=" + option.second : "");
394 });
395 socketContext->sendToPeer("Set-Cookie: " + cookieString + "\r\n");
396 }
397
398 socketContext->sendToPeer("\r\n");
399 }
400
401 return *this;
402 }
static std::string reason(int status)
void responseStarted(const Response &response)

References cookies, web::http::CookieOptions::getOptions(), web::http::CookieOptions::getValue(), headers, httpMajor, httpMinor, isConnected(), web::http::StatusCode::reason(), web::http::server::SocketContext::responseStarted(), core::socket::SocketContext::sendToPeer(), set(), socketContext, statusCode, and httputils::to_http_date().

Referenced by onSourceConnect(), send(), and express::Response::sendHeader().

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

◆ sendStatus()

void web::http::server::Response::sendStatus ( int  statusCode)

Definition at line 236 of file Response.cpp.

236 {
238
240 }

References web::http::StatusCode::reason(), send(), and status().

Here is the call graph for this function:

◆ set() [1/2]

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

Definition at line 122 of file Response.cpp.

122 {
123 for (const auto& [field, value] : headers) {
124 set(field, value, overwrite);
125 }
126
127 return *this;
128 }

References set().

Referenced by express::Response::set().

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

◆ set() [2/2]

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

Definition at line 130 of file Response.cpp.

130 {
131 if (!value.empty()) {
132 if (overwrite) {
133 headers.insert_or_assign(field, value);
134 } else {
135 headers.insert({field, value});
136 }
137
138 if (web::http::ciEquals(field, "Connection")) {
139 if (web::http::ciContains(headers[field], "keep-alive")) {
141 } else if (web::http::ciContains(headers[field], "close")) {
143 }
144 } else if (web::http::ciEquals(field, "Content-Length")) {
145 contentLength = std::stoul(value);
147 headers.erase("Transfer-Encoding");
148 } else if (web::http::ciEquals(field, "Transfer-Encoding")) {
149 if (web::http::ciContains(headers[field], "chunked")) {
151 headers.erase("Content-Length");
152 }
153 if (web::http::ciContains(headers[field], "compressed")) {
154 }
155 if (web::http::ciContains(headers[field], "deflate")) {
156 }
157 if (web::http::ciContains(headers[field], "gzip")) {
158 }
159 } else if (web::http::ciEquals(field, "Content-Encoding")) {
160 if (web::http::ciContains(headers[field], "compressed")) {
161 }
162 if (web::http::ciContains(headers[field], "deflate")) {
163 }
164 if (web::http::ciContains(headers[field], "gzip")) {
165 }
166 if (web::http::ciContains(headers[field], "br")) {
167 }
168 }
169 } else {
170 headers.erase(field);
171 }
172
173 return *this;
174 }
bool ciEquals(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(), web::websocket::server::SocketContextUpgradeFactory::create(), web::http::server::SocketContext::deliverRequest(), send(), send(), sendFile(), sendHeader(), set(), express::Response::set(), setTrailer(), type(), and upgrade().

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

◆ setTrailer()

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

Definition at line 196 of file Response.cpp.

196 {
197 if (!value.empty()) {
198 if (overwrite) {
199 trailer.insert_or_assign(field, value);
200 } else {
201 trailer.insert({field, value});
202 }
203 if (!headers.contains("Trailer")) {
204 set("Trailer", field);
205 } else {
206 headers["Trailer"].append("," + field);
207 }
208 } else {
209 trailer.erase(field);
210 }
211
212 return *this;
213 }

References headers, set(), and trailer.

Referenced by express::Response::setTrailer().

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

◆ status()

Response & web::http::server::Response::status ( int  statusCode)

Definition at line 104 of file Response.cpp.

104 {
105 this->statusCode = statusCode;
106
107 return *this;
108 }

References statusCode.

Referenced by web::websocket::server::SocketContextUpgradeFactory::create(), web::http::server::SocketContext::deliverRequest(), sendFile(), sendStatus(), express::Response::status(), and upgrade().

Here is the caller graph for this function:

◆ type()

Response & web::http::server::Response::type ( const std::string &  type)

Definition at line 176 of file Response.cpp.

176 {
177 return set("Content-Type", type);
178 }
Response & type(const std::string &type)
Definition Response.cpp:176

References set().

Referenced by express::Response::type().

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

◆ upgrade()

void web::http::server::Response::upgrade ( const std::shared_ptr< Request > &  request,
const std::function< void(const std::string &)> &  status 
)

Sequence diagram of res.upgrade(req).

Definition at line 248 of file Response.cpp.

248 {
249 if (isConnected()) {
250 const std::string connectionName = socketContext->getSocketConnection()->getConnectionName();
251
252 std::string name;
253
254 if (request != nullptr) {
255 LOG(DEBUG) << connectionName << " HTTP: Initiating upgrade: " << request->method << " " << request->url
256 << " HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor) << "\n"
257 << httputils::toString(request->method,
258 request->url,
259 "HTTP/" + std::to_string(request->httpMajor) + "." + std::to_string(request->httpMinor),
260 request->queries,
261 request->headers,
262 {},
263 request->cookies,
264 std::vector<char>());
265 if (web::http::ciContains(request->get("connection"), "Upgrade")) {
266 SocketContextUpgradeFactory* socketContextUpgradeFactory =
268
269 if (socketContextUpgradeFactory != nullptr) {
270 name = socketContextUpgradeFactory->name();
271
272 LOG(DEBUG) << connectionName << " HTTP upgrade: SocketContextUpgradeFactory create success for: " << name;
273
274 core::socket::stream::SocketContext* socketContextUpgrade =
275 socketContextUpgradeFactory->create(socketContext->getSocketConnection());
276
277 if (socketContextUpgrade != nullptr) {
278 LOG(DEBUG) << connectionName << " HTTP upgrade: SocketContextUpgrade create success for: " << name;
279
280 LOG(DEBUG) << connectionName << " HTTP upgrade: Response to upgrade request: " << request->method << " "
281 << request->url << " " << "HTTP/" << request->httpMajor << "." << request->httpMinor << "\n"
282 << httputils::toString("HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor),
283 std::to_string(statusCode),
285 headers,
286 cookies,
287 {});
288
289 socketContext->switchSocketContext(socketContextUpgrade);
290 } else {
291 LOG(DEBUG) << connectionName << " HTTP upgrade: SocketContextUpgrade create failed for: " << name;
292
293 set("Connection", "close").status(404);
294 }
295 } else {
296 LOG(DEBUG) << connectionName
297 << " SocketContextUpgradeFactory create failed for all of: " << request->get("upgrade");
298
299 set("Connection", "close").status(404);
300 }
301 } else {
302 LOG(DEBUG) << connectionName << " HTTP upgrade: No upgrade requested";
303
304 set("Connection", "close").status(400);
305 }
306 } else {
307 LOG(ERROR) << connectionName << " HTTP upgrade: Request has gone away";
308
309 set("Connection", "close").status(500);
310 }
311
312 LOG(DEBUG) << connectionName << " HTTP: Upgrade bootstrap " << (!name.empty() ? "success" : "failed");
313 LOG(DEBUG) << " Protocol selected: " << name;
314 LOG(DEBUG) << " requested: " << request->get("upgrade");
315 LOG(DEBUG) << " Subprotocol selected: " << header("upgrade");
316 LOG(DEBUG) << " requested: " << request->get("Sec-WebSocket-Protocol");
317
318 status(name);
319 } else {
320 LOG(ERROR) << "HTTP upgrade: Unexpected disconnect";
321 }
322 }
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const
void switchSocketContext(SocketContext *newSocketContext)
const std::string & header(const std::string &field)
Definition Response.cpp:481
SocketContextUpgradeFactory * select(Request &req, Response &res) override
std::string toString(const std::string &method, const std::string &url, const std::string &version, const web::http::CiStringMap< std::string > &queries, const web::http::CiStringMap< std::string > &header, const web::http::CiStringMap< std::string > &trailer, const web::http::CiStringMap< std::string > &cookies, const std::vector< char > &body)

References web::http::ciContains(), web::http::server::Request::cookies, cookies, web::http::SocketContextUpgradeFactory< RequestT, ResponseT >::create(), web::http::server::Request::get(), core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), header(), web::http::server::Request::headers, headers, web::http::server::Request::httpMajor, httpMajor, web::http::server::Request::httpMinor, httpMinor, web::http::server::SocketContextUpgradeFactorySelector::instance(), isConnected(), web::http::server::Request::method, web::http::SocketContextUpgradeFactory< RequestT, ResponseT >::name(), web::http::server::Request::queries, web::http::StatusCode::reason(), web::http::server::SocketContextUpgradeFactorySelector::select(), set(), socketContext, status(), statusCode, core::socket::stream::SocketContext::switchSocketContext(), httputils::toString(), httputils::toString(), and web::http::server::Request::url.

Referenced by express::Response::upgrade().

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

Friends And Related Symbol Documentation

◆ SocketContext

friend class SocketContext
friend

Definition at line 140 of file Response.h.

Member Data Documentation

◆ connectionState

ConnectionState web::http::server::Response::connectionState = ConnectionState::Default
private

Definition at line 137 of file Response.h.

Referenced by init(), web::http::server::SocketContext::requestCompleted(), and set().

◆ contentLength

std::size_t web::http::server::Response::contentLength = 0
private

Definition at line 133 of file Response.h.

Referenced by init(), sendCompleted(), sendFragment(), and set().

◆ contentSent

std::size_t web::http::server::Response::contentSent = 0
private

Definition at line 132 of file Response.h.

Referenced by init(), sendCompleted(), and sendFragment().

◆ cookies

web::http::CiStringMap<web::http::CookieOptions> web::http::server::Response::cookies
protected

Definition at line 128 of file Response.h.

Referenced by cookie(), init(), sendHeader(), and upgrade().

◆ headers

web::http::CiStringMap<std::string> web::http::server::Response::headers
protected

Definition at line 127 of file Response.h.

Referenced by append(), header(), init(), sendFragment(), sendHeader(), set(), setTrailer(), and upgrade().

◆ httpMajor

◆ httpMinor

◆ requestMethod

std::string web::http::server::Response::requestMethod = "GET"

Definition at line 121 of file Response.h.

Referenced by web::http::server::SocketContext::deliverRequest().

◆ socketContext

web::http::server::SocketContext* web::http::server::Response::socketContext = nullptr
private

◆ statusCode

◆ trailer

web::http::CiStringMap<std::string> web::http::server::Response::trailer
protected

Definition at line 129 of file Response.h.

Referenced by init(), sendCompleted(), and setTrailer().

◆ transferEncoding

TransferEncoding web::http::server::Response::transferEncoding = TransferEncoding::HTTP10
private

Definition at line 138 of file Response.h.

Referenced by init(), sendCompleted(), sendFragment(), and set().


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