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

36 : responseBase(response) {
37 }
std::shared_ptr< web::http::server::Response > responseBase
Definition Response.h:74

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

39 {
40 }

Member Function Documentation

◆ append()

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

Definition at line 97 of file Response.cpp.

97 {
98 responseBase->append(field, value);
99
100 return *this;
101 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:86

◆ attachment()

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

Definition at line 73 of file Response.cpp.

73 {
74 set("Content-Disposition", "attachment" + ((!fileName.empty()) ? ("; filename=\"" + fileName + "\"") : ""));
75
76 return *this;
77 }
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:103

◆ clearCookie()

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

Definition at line 127 of file Response.cpp.

127 {
128 responseBase->clearCookie(name, options);
129
130 return *this;
131 }
Response & clearCookie(const std::string &name, const std::map< std::string, std::string > &options={})
Definition Response.cpp:162

◆ cookie()

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

Definition at line 121 of file Response.cpp.

121 {
122 responseBase->cookie(name, value, options);
123
124 return *this;
125 }
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
Definition Response.cpp:156

◆ download() [1/2]

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

Definition at line 51 of file Response.cpp.

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

◆ download() [2/2]

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

Definition at line 55 of file Response.cpp.

55 {
56 attachment(fileName);
57 sendFile(file, onError);
58 }
Response & attachment(const std::string &fileName="")
Definition Response.cpp:73
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:155

◆ end()

void express::Response::end ( )

Definition at line 151 of file Response.cpp.

151 {
152 responseBase->end();
153 }

◆ getSocketContext()

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

Definition at line 42 of file Response.cpp.

42 {
44 }
SocketContext * getSocketContext() const
Definition Response.cpp:432

◆ header()

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

Definition at line 177 of file Response.cpp.

177 {
178 return responseBase->header(field);
179 }
const std::string & header(const std::string &field)
Definition Response.cpp:428

◆ json()

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

Definition at line 46 of file Response.cpp.

46 {
47 set("Content-Type", "application/json");
48 send(json.dump());
49 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:139
void json(const nlohmann::json &json)
Definition Response.cpp:46

◆ location()

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

Definition at line 79 of file Response.cpp.

79 {
80 set("Location", loc);
81
82 return *this;
83 }

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

60 {
61 redirect(302, loc);
62 }
void redirect(const std::string &loc)
Definition Response.cpp:60

◆ redirect() [2/2]

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

Definition at line 64 of file Response.cpp.

64 {
65 location(loc);
66 sendStatus(state);
67 }
void sendStatus(int state)
Definition Response.cpp:69
Response & location(const std::string &loc)
Definition Response.cpp:79

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

139 {
140 responseBase->send(chunk, chunkLen);
141 }
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:191

◆ send() [2/2]

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

Definition at line 143 of file Response.cpp.

143 {
144 responseBase->send(chunk);
145 }

◆ sendFile()

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

Definition at line 155 of file Response.cpp.

155 {
156 responseBase->sendFile(file, callback);
157 }
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:270

◆ sendFragment() [1/2]

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

Definition at line 165 of file Response.cpp.

165 {
166 responseBase->sendFragment(chunk, chunkLen);
167
168 return *this;
169 }
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:346

◆ sendFragment() [2/2]

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

Definition at line 171 of file Response.cpp.

171 {
173
174 return *this;
175 }

◆ sendHeader()

Response & express::Response::sendHeader ( )

Definition at line 159 of file Response.cpp.

159 {
161
162 return *this;
163 }

◆ sendStatus()

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

Definition at line 69 of file Response.cpp.

69 {
70 this->status(state).send(web::http::StatusCode::reason(state) + "\r\n");
71 }
Response & status(int status)
Definition Response.cpp:91
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 109 of file Response.cpp.

109 {
110 responseBase->set(headers, overwrite);
111
112 return *this;
113 }
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:106

◆ set() [2/2]

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

Definition at line 103 of file Response.cpp.

103 {
104 responseBase->set(field, value, overwrite);
105
106 return *this;
107 }

◆ setTrailer()

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

Definition at line 133 of file Response.cpp.

133 {
134 responseBase->setTrailer(field, value, overwrite);
135
136 return *this;
137 }
Response & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:172

◆ status()

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

Definition at line 91 of file Response.cpp.

91 {
93
94 return *this;
95 }
Response & status(int statusCode)
Definition Response.cpp:80

◆ type()

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

Definition at line 115 of file Response.cpp.

115 {
117
118 return *this;
119 }
Response & type(const std::string &type)
Definition Response.cpp:115
Response & type(const std::string &type)
Definition Response.cpp:152

◆ upgrade()

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

Definition at line 147 of file Response.cpp.

147 {
148 responseBase->upgrade(request->requestBase, status);
149 }
void upgrade(const std::shared_ptr< Request > &request, const std::function< void(const std::string &)> &status)
Definition Response.cpp:222

◆ vary()

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

Definition at line 85 of file Response.cpp.

85 {
86 append("Vary", field);
87
88 return *this;
89 }
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:97

Member Data Documentation

◆ responseBase

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

Definition at line 74 of file Response.h.


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