-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResponse.hpp
72 lines (56 loc) · 2.19 KB
/
Response.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include "Request.hpp"
#include "socket/kqueue.hpp"
class HttpResponse {
public:
static std::unordered_map<std::string, std::string> files_cache;
private:
int _status;
size_t _content_length;
std::string _version;
std::string _action;
std::unordered_multimap<std::string, std::string> _headers;
std::vector<std::string> _body;
public:
HttpResponse(int status,
const std::string& version,
const std::string& action);
HttpResponse(int status,
const std::string& version,
const std::string& action,
const HttpRequest& request);
HttpResponse& add_header(const std::string& key, const std::string& value);
std::string getHeaderValue(const std::string& key) const;
HttpResponse& add_to_body(const std::string& line);
HttpResponse& add_to_body(const std::vector<std::string>& body);
HttpResponse& add_content_type(const std::string& path);
size_t get_body_size() const;
std::string build();
void dump() const;
public:
static std::string generateErrorPage(int statusCode,
const std::string& statusMessage);
static std::string get_content_type(const std::string& location);
static HttpResponse error_response(int status, const std::string& file);
static HttpResponse send_file(
Kqueue& q,
const std::string& file,
const std::string& root,
std::unordered_map<int, std::string>& error_pages);
static HttpResponse redirect_moved_response(const std::string& location);
static HttpResponse redirect_found_response(const std::string& location);
static HttpResponse index_response(
Kqueue& q,
const std::vector<std::string>& index,
const std::string& root,
std::unordered_map<int, std::string>& error_pages);
static HttpResponse generate_indexing(const std::string& dir,
const std::string& location);
static void updateFileCache(const std::string& full_path);
};