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()) {
78 socketContext->streamEof();
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=nullptr)
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 364 of file Response.cpp.

364 {
365 send("");
366 }
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 495 of file Response.cpp.

495 {
496 return socketContext;
497 }

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 491 of file Response.cpp.

491 {
492 return headers[field];
493 }

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 454 of file Response.cpp.

454 {
455 if (isConnected()) {
456 if (socketContext->streamToPeer(source)) {
457 sendHeader();
458
459 source->start();
460 } else {
461 source->stop();
462 }
463 } else {
464 source->stop();
465 }
466 }
Source * source
Definition Sink.h:90

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 468 of file Response.cpp.

468 {
469 sendFragment(chunk, chunkLen);
470 }
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:405

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 472 of file Response.cpp.

472 {
473 if (isConnected()) {
474 socketContext->streamEof();
475 }
476
478 }

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 480 of file Response.cpp.

480 {
481 errno = errnum;
482
483 if (isConnected()) {
484 socketContext->streamEof();
485 socketContext->close();
486 }
487
489 }

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 431 of file Response.cpp.

431 {
432 if (isConnected()) {
434 sendFragment(""); // For transfer encoding chunked. Terminate the chunk sequence.
435
436 if (!trailer.empty()) {
437 for (auto& [field, value] : trailer) {
438 socketContext->sendToPeer(std::string(field).append(":").append(value).append("\r\n"));
439 }
440
441 socketContext->sendToPeer("\r\n");
442 }
443 }
444
445 const bool isHead = (requestMethod == "HEAD");
446 if (isHead) {
447 // Pretend we sent the full body length; this prevents keep-alive logic from treating HEAD as incomplete.
449 }
450 socketContext->responseCompleted(*this, isHead || contentSent == contentLength || (httpMajor == 1 && httpMinor == 0));
451 }
452 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:110

References web::http::Chunked, contentLength, contentSent, httpMajor, httpMinor, isConnected(), requestMethod, 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 status(200);
338 set("Content-Type", web::http::MimeTypes::contentType(absolutFileName), false);
339 set("Last-Modified", httputils::file_mod_http_date(absolutFileName), false);
340 if (httpMajor == 1) {
341 if (httpMinor == 1) {
342 set("Transfer-Encoding", "chunked");
343 } else {
344 set("Content-Length", std::to_string(std::filesystem::file_size(absolutFileName)));
345 }
346 }
347 } else {
348 status(404);
349 }
350 })->pipe(this);
351 } else {
352 status(404);
353 errno = EEXIST;
354 onStatus(errno);
355 }
356 } else {
357 status(404);
358 errno = ENOENT;
359 onStatus(errno);
360 }
361 }
362 }
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 405 of file Response.cpp.

405 {
406 // RFC 9110 / Express semantics: HEAD responses must not include a message body.
407 if (requestMethod == "HEAD") {
408 return *this;
409 }
410 if (isConnected()) {
412 socketContext->sendToPeer(to_hex_str(chunkLen).append("\r\n"));
413 }
414
415 socketContext->sendToPeer(chunk, chunkLen);
416 contentSent += chunkLen;
417
418 if (transferEncoding == TransferEncoding::Chunked || web::http::ciContains(headers["Content-Type"], "text/event-stream")) {
419 socketContext->sendToPeer("\r\n");
420 contentLength += chunkLen;
421 }
422 }
423
424 return *this;
425 }
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(), requestMethod, core::socket::SocketContext::sendToPeer(), core::socket::stream::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 427 of file Response.cpp.

427 {
428 return sendFragment(chunk.data(), chunk.size());
429 }

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 368 of file Response.cpp.

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

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(), express::Response::set(), 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->getSocketConnection()->setSocketContext(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 & header(const std::string &field)
Definition Response.cpp:491
SocketContextUpgradeFactory * select(Request &req, Response &res) override
std::string toString(const std::string &method, const std::string &url, const std::string &version, const std::map< std::string, 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(), core::socket::stream::SocketConnection::setSocketContext(), socketContext, status(), statusCode, 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:

◆ 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

◆ 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"

◆ 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: