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 ()
 
bool isConnected () const
 
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:97

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

123 {
124 responseBase->append(field, value);
125
126 return *this;
127 }

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

99 {
100 set("Content-Disposition", "attachment" + ((!fileName.empty()) ? ("; filename=\"" + fileName + "\"") : ""));
101
102 return *this;
103 }
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:129

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

153 {
154 responseBase->clearCookie(name, options);
155
156 return *this;
157 }

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

147 {
148 responseBase->cookie(name, value, options);
149
150 return *this;
151 }

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

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

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

81 {
82 attachment(fileName);
83 sendFile(file, onError);
84 }
Response & attachment(const std::string &fileName="")
Definition Response.cpp:99
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:181

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

177 {
178 responseBase->end();
179 }

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

68 {
69 return responseBase->getSocketContext();
70 }

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

Referenced by express::dispatcher::ApplicationDispatcher::dispatch(), express::dispatcher::MiddlewareDispatcher::dispatch(), express::dispatcher::RouterDispatcher::dispatch(), main(), 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 203 of file Response.cpp.

203 {
204 return responseBase->header(field);
205 }

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

Here is the call graph for this function:

◆ isConnected()

bool express::Response::isConnected ( ) const

Definition at line 64 of file Response.cpp.

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

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

Here is the call graph for this function:

◆ json()

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

Definition at line 72 of file Response.cpp.

72 {
73 set("Content-Type", "application/json");
74 send(json.dump());
75 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:165
void json(const nlohmann::json &json)
Definition Response.cpp:72

References send(), and set().

Here is the call graph for this function:

◆ location()

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

Definition at line 105 of file Response.cpp.

105 {
106 set("Location", loc);
107
108 return *this;
109 }

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

86 {
87 redirect(302, loc, html);
88 }
void redirect(const std::string &loc, const std::string &html={})
Definition Response.cpp:86

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

90 {
91 location(loc);
92 sendStatus(state, html);
93 }
void sendStatus(int state, const std::string &html={})
Definition Response.cpp:95
Response & location(const std::string &loc)
Definition Response.cpp:105

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

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

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

169 {
170 responseBase->send(chunk);
171 }

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

181 {
182 responseBase->sendFile(file, callback);
183 }

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

191 {
192 responseBase->sendFragment(chunk, chunkLen);
193
194 return *this;
195 }

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

197 {
198 responseBase->sendFragment(chunk);
199
200 return *this;
201 }

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

Here is the call graph for this function:

◆ sendHeader()

Response & express::Response::sendHeader ( )

Definition at line 185 of file Response.cpp.

185 {
186 responseBase->sendHeader();
187
188 return *this;
189 }

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

95 {
96 this->status(state).send(!html.empty() ? html : web::http::StatusCode::reason(state) + "\r\n");
97 }
Response & status(int status)
Definition Response.cpp:117
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 135 of file Response.cpp.

135 {
136 responseBase->set(headers, overwrite);
137
138 return *this;
139 }

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

129 {
130 responseBase->set(field, value, overwrite);
131
132 return *this;
133 }

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

159 {
160 responseBase->setTrailer(field, value, overwrite);
161
162 return *this;
163 }

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

117 {
118 responseBase->status(status);
119
120 return *this;
121 }

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

141 {
142 responseBase->type(type);
143
144 return *this;
145 }
Response & type(const std::string &type)
Definition Response.cpp:141

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

173 {
174 responseBase->upgrade(request->requestBase, status);
175 }

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

111 {
112 append("Vary", field);
113
114 return *this;
115 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:123

References append().

Here is the call graph for this function:

Member Data Documentation

◆ responseBase


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