-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequest.hpp
93 lines (79 loc) · 2.33 KB
/
Request.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#define BUFFER_SIZE 10906
#include <string>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>
#include <unordered_map>
#include <sys/socket.h>
#include "ClientState.hpp"
#include "Location.hpp"
#include <filesystem>
#include "Server.hpp"
enum class HostPort
{
HOST,
PORT,
};
class Request {
public:
Request(/* args */);
Request(std::string& request_headers, const Logger& logger, int socket_fd);
~Request();
void parseHeaders();
void extractPath();
void setHostPortFromHeaders( void );
void setMethod(const std::string& method);
void setBody(const std::string& body);
ClientState readFromClient(int client_fd);
const std::string& getBody() const;
const std::string& getURI() const;
const std::string& getFinalPath() const;
const std::string& getRedirPath() const;
const Location& getLocation() const;
const HTTPMethod& getMethod() const;
const std::string& getRequest() const;
const bool& getAutoindex() const;
size_t getContentLength() const;
const bool& getKeepAlive() const;
// std::size_t getMaxBodySize() const;
bool getChunkedRequest() const;
bool hasBody( void ) const;
std::string extractHostPort(HostPort get);
std::pair<std::string,int> getHostPort() const;
const std::string& getHost( void ) const;
int getPort( void ) const;
int getSocketFD() const;
const std::unordered_map<std::string, std::string>& getHeaders() const;
void handleLocation(Server *server);
std::string m_total_request;
private:
Logger l = Logger("Request");
std::string m_body;
size_t m_bytes_read = 0;
size_t m_content_length = 0;
HTTPMethod m_method = HTTPMethod::UNDEFINED;
std::string m_uri;
std::unordered_map<std::string, std::string> m_headers;
bool m_keep_alive = false;
std::string m_redirection_path;
std::string m_final_path;
Location* m_loc = nullptr;
bool m_auto_index = false;
int port;
std::string host;
// The listen sockets we received this request on
int socket_fd = -1;
public:
class Exception : public std::exception {
private:
const std::string message;
public:
Exception(const std::string& message) : message("Invalid request: " + message) { }
virtual const char* what() const throw() {
return message.c_str();
}
};
};