SNode.C
Loading...
Searching...
No Matches
express::Response Class Reference

#include <Response.h>

Collaboration diagram for express::Response:

Public Member Functions

 Response (const std::shared_ptr< web::http::server::Response > &response) noexcept
 
 Response (Response &)=delete
 
 Response (Response &&) noexcept=delete
 
Responseoperator= (Response &)=delete
 
Responseoperator= (Response &&) noexcept=delete
 
 ~Response ()
 
web::http::server::SocketContextgetSocketContext () const
 
void json (const nlohmann::json &json)
 
void download (const std::string &file, const std::function< void(int)> &onError)
 
void download (const std::string &file, const std::string &fileName, const std::function< void(int)> &onError)
 
void redirect (const std::string &loc, const std::string &html={})
 
void redirect (int state, const std::string &loc, const std::string &html={})
 
void sendStatus (int state, const std::string &html={})
 
Responseattachment (const std::string &fileName="")
 
Responselocation (const std::string &loc)
 
Responsevary (const std::string &field)
 
Responsestatus (int status)
 
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 upgrade (const std::shared_ptr< Request > &request, const std::function< void(const std::string)> &status)
 
void end ()
 
void sendFile (const std::string &file, const std::function< void(int)> &callback)
 
ResponsesendHeader ()
 
ResponsesendFragment (const char *chunk, std::size_t chunkLen)
 
ResponsesendFragment (const std::string &chunk)
 
const std::string & header (const std::string &field)
 

Private Attributes

std::shared_ptr< web::http::server::ResponseresponseBase
 

Detailed Description

Definition at line 67 of file Response.h.

Constructor & Destructor Documentation

◆ Response() [1/3]

express::Response::Response ( const std::shared_ptr< web::http::server::Response > &  response)
explicitnoexcept

Definition at line 57 of file Response.cpp.

58 : responseBase(response) {
59 }
std::shared_ptr< web::http::server::Response > responseBase
Definition Response.h:96

References responseBase.

◆ Response() [2/3]

express::Response::Response ( Response )
explicitdelete

◆ Response() [3/3]

express::Response::Response ( Response &&  )
explicitdeletenoexcept

◆ ~Response()

express::Response::~Response ( )

Definition at line 61 of file Response.cpp.

61 {
62 }

Member Function Documentation

◆ append()

Response & express::Response::append ( const std::string &  field,
const std::string &  value 
)

Definition at line 119 of file Response.cpp.

119 {
120 responseBase->append(field, value);
121
122 return *this;
123 }

References web::http::server::Response::append(), and responseBase.

Referenced by vary().

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

◆ attachment()

Response & express::Response::attachment ( const std::string &  fileName = "")

Definition at line 95 of file Response.cpp.

95 {
96 set("Content-Disposition", "attachment" + ((!fileName.empty()) ? ("; filename=\"" + fileName + "\"") : ""));
97
98 return *this;
99 }
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:125

References set().

Referenced by download().

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

◆ clearCookie()

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

Definition at line 149 of file Response.cpp.

149 {
150 responseBase->clearCookie(name, options);
151
152 return *this;
153 }

References web::http::server::Response::clearCookie(), and responseBase.

Here is the call graph for this function:

◆ cookie()

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

Definition at line 143 of file Response.cpp.

143 {
144 responseBase->cookie(name, value, options);
145
146 return *this;
147 }

References web::http::server::Response::cookie(), and responseBase.

Referenced by express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ download() [1/2]

void express::Response::download ( const std::string &  file,
const std::function< void(int)> &  onError 
)

Definition at line 73 of file Response.cpp.

73 {
74 download(file, std::filesystem::path(file).filename(), onError);
75 }
void download(const std::string &file, const std::function< void(int)> &onError)
Definition Response.cpp:73

References download().

Here is the call graph for this function:

◆ download() [2/2]

void express::Response::download ( const std::string &  file,
const std::string &  fileName,
const std::function< void(int)> &  onError 
)

Definition at line 77 of file Response.cpp.

77 {
78 attachment(fileName);
79 sendFile(file, onError);
80 }
Response & attachment(const std::string &fileName="")
Definition Response.cpp:95
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:177

References attachment(), and sendFile().

Referenced by download().

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

◆ end()

void express::Response::end ( )

Definition at line 173 of file Response.cpp.

173 {
174 responseBase->end();
175 }

References web::http::server::Response::end(), and responseBase.

Referenced by main().

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

◆ getSocketContext()

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

Definition at line 64 of file Response.cpp.

64 {
65 return responseBase->getSocketContext();
66 }

References web::http::server::Response::getSocketContext(), and responseBase.

Referenced by express::middleware::StaticMiddleware::StaticMiddleware(), and express::middleware::VerboseRequest::VerboseRequest().

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

◆ header()

const std::string & express::Response::header ( const std::string &  field)

Definition at line 199 of file Response.cpp.

199 {
200 return responseBase->header(field);
201 }

References web::http::server::Response::header(), and responseBase.

Here is the call graph for this function:

◆ json()

void express::Response::json ( const nlohmann::json &  json)

Definition at line 68 of file Response.cpp.

68 {
69 set("Content-Type", "application/json");
70 send(json.dump());
71 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:161
void json(const nlohmann::json &json)
Definition Response.cpp:68

References send(), and set().

Here is the call graph for this function:

◆ location()

Response & express::Response::location ( const std::string &  loc)

Definition at line 101 of file Response.cpp.

101 {
102 set("Location", loc);
103
104 return *this;
105 }

References set().

Referenced by redirect().

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

◆ operator=() [1/2]

Response & express::Response::operator= ( Response &&  )
deletenoexcept

◆ operator=() [2/2]

Response & express::Response::operator= ( Response )
delete

◆ redirect() [1/2]

void express::Response::redirect ( const std::string &  loc,
const std::string &  html = {} 
)

Definition at line 82 of file Response.cpp.

82 {
83 redirect(302, loc, html);
84 }
void redirect(const std::string &loc, const std::string &html={})
Definition Response.cpp:82

References redirect().

Here is the call graph for this function:

◆ redirect() [2/2]

void express::Response::redirect ( int  state,
const std::string &  loc,
const std::string &  html = {} 
)

Definition at line 86 of file Response.cpp.

86 {
87 location(loc);
88 sendStatus(state, html);
89 }
void sendStatus(int state, const std::string &html={})
Definition Response.cpp:91
Response & location(const std::string &loc)
Definition Response.cpp:101

References location(), and sendStatus().

Referenced by redirect(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ send() [1/2]

void express::Response::send ( const char *  chunk,
std::size_t  chunkLen 
)

Definition at line 161 of file Response.cpp.

161 {
162 responseBase->send(chunk, chunkLen);
163 }

References responseBase, and web::http::server::Response::send().

Here is the call graph for this function:

◆ send() [2/2]

void express::Response::send ( const std::string &  chunk)

Definition at line 165 of file Response.cpp.

165 {
166 responseBase->send(chunk);
167 }

References responseBase, and web::http::server::Response::send().

Referenced by json(), main(), sendStatus(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ sendFile()

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

Definition at line 177 of file Response.cpp.

177 {
178 responseBase->sendFile(file, callback);
179 }

References responseBase, and web::http::server::Response::sendFile().

Referenced by download(), main(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ sendFragment() [1/2]

Response & express::Response::sendFragment ( const char *  chunk,
std::size_t  chunkLen 
)

Definition at line 187 of file Response.cpp.

187 {
188 responseBase->sendFragment(chunk, chunkLen);
189
190 return *this;
191 }

References responseBase, and web::http::server::Response::sendFragment().

Here is the call graph for this function:

◆ sendFragment() [2/2]

Response & express::Response::sendFragment ( const std::string &  chunk)

Definition at line 193 of file Response.cpp.

193 {
194 responseBase->sendFragment(chunk);
195
196 return *this;
197 }

References responseBase, and web::http::server::Response::sendFragment().

Here is the call graph for this function:

◆ sendHeader()

Response & express::Response::sendHeader ( )

Definition at line 181 of file Response.cpp.

181 {
182 responseBase->sendHeader();
183
184 return *this;
185 }

References responseBase, and web::http::server::Response::sendHeader().

Here is the call graph for this function:

◆ sendStatus()

void express::Response::sendStatus ( int  state,
const std::string &  html = {} 
)

Definition at line 91 of file Response.cpp.

91 {
92 this->status(state).send(!html.empty() ? html : web::http::StatusCode::reason(state) + "\r\n");
93 }
Response & status(int status)
Definition Response.cpp:113
Definition Client.h:52

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

Referenced by express::middleware::BasicAuthentication::BasicAuthentication(), express::RootRoute::dispatch(), main(), redirect(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ set() [1/2]

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

Definition at line 131 of file Response.cpp.

131 {
132 responseBase->set(headers, overwrite);
133
134 return *this;
135 }

References responseBase, and web::http::server::Response::set().

Referenced by express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ set() [2/2]

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

Definition at line 125 of file Response.cpp.

125 {
126 responseBase->set(field, value, overwrite);
127
128 return *this;
129 }

References responseBase, and web::http::server::Response::set().

Referenced by attachment(), express::middleware::BasicAuthentication::BasicAuthentication(), json(), location(), main(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ setTrailer()

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

Definition at line 155 of file Response.cpp.

155 {
156 responseBase->setTrailer(field, value, overwrite);
157
158 return *this;
159 }

References responseBase, and web::http::server::Response::setTrailer().

Here is the call graph for this function:

◆ status()

Response & express::Response::status ( int  status)

Definition at line 113 of file Response.cpp.

113 {
114 responseBase->status(status);
115
116 return *this;
117 }

References responseBase, and web::http::server::Response::status().

Referenced by main(), sendStatus(), and express::middleware::StaticMiddleware::StaticMiddleware().

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

◆ type()

Response & express::Response::type ( const std::string &  type)

Definition at line 137 of file Response.cpp.

137 {
138 responseBase->type(type);
139
140 return *this;
141 }
Response & type(const std::string &type)
Definition Response.cpp:137

References responseBase, and web::http::server::Response::type().

Here is the call graph for this function:

◆ upgrade()

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

Definition at line 169 of file Response.cpp.

169 {
170 responseBase->upgrade(request->requestBase, status);
171 }

References express::Request::requestBase, responseBase, and web::http::server::Response::upgrade().

Referenced by main().

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

◆ vary()

Response & express::Response::vary ( const std::string &  field)

Definition at line 107 of file Response.cpp.

107 {
108 append("Vary", field);
109
110 return *this;
111 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:119

References append().

Here is the call graph for this function:

Member Data Documentation

◆ responseBase

std::shared_ptr<web::http::server::Response> express::Response::responseBase
private

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