Malloy
Loading...
Searching...
No Matches
generator.hpp
1#pragma once
2
3#include "response.hpp"
4#include "request.hpp"
5#include "type_traits.hpp"
6#include "types.hpp"
7#include "utils.hpp"
8
9#include <filesystem>
10#include <string_view>
11#include <variant>
12
13namespace malloy::http
14{
15
22 {
29 using file_response = std::variant<response<boost::beast::http::file_body>, response<boost::beast::http::string_body>>;
30
31 public:
35 generator() = default;
36
37 generator(const generator& other) = delete;
38 generator(generator&& other) = delete;
39
43 virtual
44 ~generator() = default;
45
46 // Operators
47 generator& operator=(const generator& rhs) = delete;
48 generator& operator=(generator&& rhs) = delete;
49
53 [[nodiscard]]
54 static
56 ok();
57
65 [[nodiscard]]
66 static
68 redirect(status code, std::string_view location);
69
76 [[nodiscard]]
77 static
79 bad_request(std::string_view reason);
80
87 [[nodiscard]]
88 static
90 not_found(std::string_view resource);
91
98 [[nodiscard]]
99 static
101 server_error(std::string_view what);
102
110 template<malloy::http::concepts::body Body>
111 [[nodiscard]]
112 static
113 file_response
114 file(const request<Body>& req, const std::filesystem::path& storage_base_path)
115 {
116 return file(storage_base_path, malloy::http::resource_string(req));
117 }
118
126 [[nodiscard]]
127 static
128 file_response
129 file(const std::filesystem::path& storage_path, std::string_view rel_path);
130 };
131
132}
Definition: generator.hpp:22
static response redirect(status code, std::string_view location)
Definition: generator.cpp:17
static file_response file(const request< Body > &req, const std::filesystem::path &storage_base_path)
Definition: generator.hpp:114
static response bad_request(std::string_view reason)
Definition: generator.cpp:27
static response not_found(std::string_view resource)
Definition: generator.cpp:37
static response ok()
Definition: generator.cpp:9
virtual ~generator()=default
static response server_error(std::string_view what)
Definition: generator.cpp:47
Definition: request.hpp:19
Definition: response.hpp:22
Definition: cookie.hpp:8
boost::beast::http::status status
Definition: types.hpp:23