version 0.2.0
This commit is contained in:
parent
d19c4efad3
commit
3dddee43f7
32 changed files with 243 additions and 1020337 deletions
|
@ -219,6 +219,8 @@ enum http_version { HTTP_0_9,
|
|||
HTTP_3_0 };
|
||||
|
||||
static std::unordered_map<std::string, http_version> const http_version_map = {
|
||||
// This is because HTTP 0.9 didn't specify version in the header
|
||||
{ "", HTTP_0_9 },
|
||||
{ "HTTP/0.9", HTTP_0_9 },
|
||||
{ "HTTP/1.0", HTTP_1_0 },
|
||||
{ "HTTP/1.1", HTTP_1_1 },
|
||||
|
|
|
@ -20,8 +20,8 @@ public:
|
|||
name_value(name_value&&) = default;
|
||||
name_value& operator=(name_value&&) = default;
|
||||
|
||||
std::string name() { return _name; }
|
||||
std::string value() { return _value; }
|
||||
std::string& name() { return _name; }
|
||||
std::string& value() { return _value; }
|
||||
|
||||
virtual std::string to_string() { return ""; }
|
||||
};
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
#include "constants.cpp"
|
||||
#include "header_query.cpp"
|
||||
#include "../socket.cpp"
|
||||
#include "../build/version.cpp"
|
||||
|
|
|
@ -19,10 +19,9 @@ private:
|
|||
std::unordered_map<std::string, query_param> _query_params; // kinda goofy, whatever
|
||||
|
||||
public:
|
||||
http_request(anthracite_socket& s)
|
||||
: _path(""), _client_ipaddr(s.get_client_ip())
|
||||
http_request(std::string& raw_data, std::string client_ip)
|
||||
: _path(""), _client_ipaddr(client_ip)
|
||||
{
|
||||
std::string raw_data = s.recv_message(HTTP_HEADER_BYTES);
|
||||
|
||||
parser_state state = METHOD;
|
||||
|
||||
|
@ -136,6 +135,25 @@ public:
|
|||
|
||||
std::string client_ip() { return _client_ipaddr; }
|
||||
|
||||
http_version get_http_version() {
|
||||
return _http_version;
|
||||
}
|
||||
|
||||
bool is_supported_version() {
|
||||
return _http_version == HTTP_1_1 || _http_version == HTTP_1_0;
|
||||
}
|
||||
|
||||
bool close_connection() {
|
||||
const auto& header = _headers.find("Connection");
|
||||
const bool found = header != _headers.end();
|
||||
|
||||
if(found && header->second.value() == "keep-alive") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string to_string()
|
||||
{
|
||||
std::string response = "";
|
||||
|
|
|
@ -32,17 +32,18 @@ public:
|
|||
std::string header_to_string()
|
||||
{
|
||||
std::string response = "";
|
||||
response += "HTTP/1.0 " + std::to_string(_status_code) + " " + http_status_map.find(_status_code)->second + "\r\n";
|
||||
response += "HTTP/1.1 " + std::to_string(_status_code) + " " + http_status_map.find(_status_code)->second + "\r\n";
|
||||
std::string content_type = "text/html";
|
||||
std::string file_extension = _filename.substr(_filename.rfind('.') + 1);
|
||||
auto mime_type = mime_types.find(file_extension);
|
||||
if (mime_type != mime_types.end()) {
|
||||
content_type = mime_type->second;
|
||||
}
|
||||
|
||||
add_header(http_header("Content-Type", content_type), false);
|
||||
add_header(http_header("Content-Length", std::to_string(_content.length())), false);
|
||||
add_header(http_header("Server", "Anthracite/0.0.1"), false);
|
||||
add_header(http_header("Origin-Server", "Anthracite/0.0.1"), false);
|
||||
add_header(http_header("Server", ANTHRACITE_FULL_VERSION_STRING), false);
|
||||
add_header(http_header("Origin-Server", ANTHRACITE_FULL_VERSION_STRING), false);
|
||||
|
||||
for (auto header : _headers) {
|
||||
response += header.second.to_string();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue