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)
 
void redirect (int state, const std::string &loc)
 
void sendStatus (int state)
 
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 Response().

Referenced by Response().

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

◆ 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 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:108

◆ 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

◆ 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 }
Response & clearCookie(const std::string &name, const std::map< std::string, std::string > &options={})
Definition Response.cpp:184

◆ 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 }
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
Definition Response.cpp:178

◆ 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

◆ 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

◆ end()

void express::Response::end ( )

Definition at line 173 of file Response.cpp.

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

◆ getSocketContext()

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

Definition at line 64 of file Response.cpp.

64 {
66 }
SocketContext * getSocketContext() const
Definition Response.cpp:454

◆ 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 }
const std::string & header(const std::string &field)
Definition Response.cpp:450

◆ 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

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

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

Definition at line 82 of file Response.cpp.

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

◆ redirect() [2/2]

void express::Response::redirect ( int state,
const std::string & loc )

Definition at line 86 of file Response.cpp.

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

References sendStatus().

Here is the call 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 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:213

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

◆ 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 }
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:292

◆ 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 }
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:368

◆ sendFragment() [2/2]

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

Definition at line 193 of file Response.cpp.

193 {
195
196 return *this;
197 }

◆ sendHeader()

Response & express::Response::sendHeader ( )

Definition at line 181 of file Response.cpp.

181 {
183
184 return *this;
185 }

◆ sendStatus()

void express::Response::sendStatus ( int state)

Definition at line 91 of file Response.cpp.

91 {
92 this->status(state).send(web::http::StatusCode::reason(state) + "\r\n");
93 }
Response & status(int status)
Definition Response.cpp:113
static std::string reason(int status)

Referenced by redirect().

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 }
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:128

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

◆ 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 }
Response & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:194

◆ status()

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

Definition at line 113 of file Response.cpp.

113 {
115
116 return *this;
117 }
Response & status(int statusCode)
Definition Response.cpp:102

◆ type()

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

Definition at line 137 of file Response.cpp.

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

◆ 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 }
void upgrade(const std::shared_ptr< Request > &request, const std::function< void(const std::string &)> &status)
Definition Response.cpp:244

◆ 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

Member Data Documentation

◆ responseBase

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

Definition at line 96 of file Response.h.


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