2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20#include "express/Response.h"
22#include "express/Request.h"
23#include "web/http/StatusCodes.h"
24#include "web/http/server/Response.h"
26#ifndef DOXYGEN_SHOULD_SKIP_THIS
29#include <nlohmann/json.hpp>
43 return responseBase->getSocketContext();
47 set(
"Content-Type",
"application/json");
51 void Response::download(
const std::string& file,
const std::function<
void(
int)>& onError) {
52 download(file, std::filesystem::path(file).filename(), onError);
55 void Response::download(
const std::string& file,
const std::string& fileName,
const std::function<
void(
int)>& onError) {
57 sendFile(file, onError);
70 this->status(state).send(web::http::StatusCode::reason(state) +
"\r\n");
74 set(
"Content-Disposition",
"attachment" + ((!fileName.empty()) ? (
"; filename=\"" + fileName +
"\"") :
""));
86 append(
"Vary", field);
92 responseBase->status(status);
98 responseBase->append(field, value);
104 responseBase->set(field, value, overwrite);
109 Response&
Response::set(
const std::map<std::string, std::string>& headers,
bool overwrite) {
110 responseBase->set(headers, overwrite);
116 responseBase->type(type);
121 Response&
Response::cookie(
const std::string& name,
const std::string& value,
const std::map<std::string, std::string>& options) {
122 responseBase->cookie(name, value, options);
127 Response&
Response::clearCookie(
const std::string& name,
const std::map<std::string, std::string>& options) {
128 responseBase->clearCookie(name, options);
134 responseBase->setTrailer(field, value, overwrite);
140 responseBase->send(chunk, chunkLen);
144 responseBase->send(chunk);
147 void Response::upgrade(
const std::shared_ptr<
Request>& request,
const std::function<
void(
const std::string)>& status) {
148 responseBase->upgrade(request->requestBase, status);
155 void Response::sendFile(
const std::string& file,
const std::function<
void(
int)>& callback) {
156 responseBase->sendFile(file, callback);
160 responseBase->sendHeader();
166 responseBase->sendFragment(chunk, chunkLen);
172 responseBase->sendFragment(chunk);
178 return responseBase->header(field);
Response & attachment(const std::string &fileName="")
void redirect(const std::string &loc)
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Response & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Response & sendFragment(const std::string &chunk)
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Response & append(const std::string &field, const std::string &value)
void send(const std::string &chunk)
Response(const std::shared_ptr< web::http::server::Response > &response) noexcept
void redirect(int state, const std::string &loc)
Response & status(int status)
void send(const char *chunk, std::size_t chunkLen)
Response & vary(const std::string &field)
Response & type(const std::string &type)
web::http::server::SocketContext * getSocketContext() const
const std::string & header(const std::string &field)
void json(const nlohmann::json &json)
void sendStatus(int state)
Response & location(const std::string &loc)