magpie
Loading...
Searching...
No Matches
Response.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5#include <unordered_map>
6#include <magpie/routing/Compile.hpp>
7#include "StatusCode.hpp"
8#include "magpie/transfer/adapters/DataAdapter.hpp"
9
10namespace magpie {
11
13struct Response {
17 std::unordered_map<std::string, std::string> headers;
18
19 const StatusCode* code;
20
21 std::shared_ptr<
23 > body;
24 // TODO: does it really make sense for the content-type to be stored like this?
25 std::string contentType = "text/plain";
26
27 Response();
28 Response(
29 const StatusCode& code,
30 std::string&& body,
31 std::string&& contentType = "text/plain"
32 );
33 Response(
34 const StatusCode& code,
35 std::shared_ptr<DataAdapter>&& bodyAdapter,
36 std::string&& contentType
37 );
38
39 Response(Response&&) = delete;
40 Response(Response&) = delete;
41
42 virtual ~Response() = default;
43
44 void setBody(std::string&& body);
45
46 Response& operator=(Response&& other) = default;
47 Response& operator=(CompressedResponse&& other);
48
59 static void redirect(
60 Response& out,
61 // TODO: I wonder if it makes sense to introduce a URI object to feal with absolute redirects in the future
62 std::string&& dest,
63 bool permanent = false
64 );
65
76 static void moved(
77 Response& out,
78 std::string&& dest
79 );
80};
81
82}
Definition DataAdapter.hpp:16
Definition CompressedResponse.hpp:21
std::unordered_map< std::string, std::string > headers
Definition Response.hpp:17
static void moved(Response &out, std::string &&dest)
Definition Response.cpp:53
static void redirect(Response &out, std::string &&dest, bool permanent=false)
Definition Response.cpp:42
Definition StatusCode.hpp:25