Skip to content

Commit

Permalink
一旦関数マップに格納しきりました
Browse files Browse the repository at this point in the history
  • Loading branch information
molhot committed Aug 23, 2023
1 parent d2af9c6 commit 4283424
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 16 deletions.
160 changes: 145 additions & 15 deletions srcs/HttpRequest/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HttpRequest::HttpRequest(const std::string &value)
std::string line;
std::string key;

ready_functionmap();
std::stringstream ss(value);
std::getline(ss, line, '\n');
this->_requestline.set_value(line);
Expand All @@ -18,6 +19,94 @@ HttpRequest::HttpRequest(const std::string &value)
}
}

void HttpRequest::ready_functionmap() const
{
this->inputvalue_functionmap["Accept"] = this->set_accept;
this->inputvalue_functionmap["Accept-CH"] = this->set_accept_ch;
this->inputvalue_functionmap["Accept-Charset"] = this->set_accept_charset;
this->inputvalue_functionmap["Accept-Encoding"] = this->set_accept_encoding;
this->inputvalue_functionmap["Accept-Language"] = this->set_accept_language;
//this->inputvalue_functionmap["Accept-Patch"] = this->set_accept_patch;
this->inputvalue_functionmap["Accept-Post"] = this->set_accept_post;
this->inputvalue_functionmap["Accept-Ranges"] = this->set_accept_ranges;
this->inputvalue_functionmap["Access-Control-Allow-Credentials"] = this->set_access_control_allow_credentials;
this->inputvalue_functionmap["Access-Control-Allow-Headers"] = this->set_access_control_allow_headers;
this->inputvalue_functionmap["Access-Control-Allow-Methods"] = this->set_access_control_allow_methods;
this->inputvalue_functionmap["Access-Control-Allow-Origin"] = this->set_access_control_allow_origin;
this->inputvalue_functionmap["Access-Control-Expose-Headers"] = this->set_access_control_expose_headers;
this->inputvalue_functionmap["Access-Control-Max-Age"] = this->set_access_control_max_age;
this->inputvalue_functionmap["Access-Control-Request-Headers"] = this->set_access_control_request_headers;
this->inputvalue_functionmap["Access-Control-Request-Method"] = this->set_access_control_request_method;
this->inputvalue_functionmap["Age"] = this->set_age;
this->inputvalue_functionmap["Allow"] = this->set_allow;
this->inputvalue_functionmap["Alt-Svc"] = this->set_alt_svc;
this->inputvalue_functionmap["Alt-Used"] = this->set_alt_used;
this->inputvalue_functionmap["Authorization"] = this->set_authorization;
// this->inputvalue_functionmap["Cache-Control"] = this->set_cache_control;
this->inputvalue_functionmap["Clear-Site-Data"] = this->set_clear_site_data;
this->inputvalue_functionmap["Connection"] = this->set_connection;
this->inputvalue_functionmap["Content-Disposition"] = this->set_content_disponesition;
this->inputvalue_functionmap["Content-Encoding"] = this->set_content_encoding;
this->inputvalue_functionmap["Content-Language"] = this->set_content_language;
this->inputvalue_functionmap["Content-Length"] = this->set_content_length;
this->inputvalue_functionmap["Content-Location"] = this->set_content_location;
this->inputvalue_functionmap["Content-Range"] = this->set_content_range;
this->inputvalue_functionmap["Content-Security-Policy"] = this->set_content_security_policy;
this->inputvalue_functionmap["Content-Security-Policy-Report-Only"] = this->set_content_security_policy_report_only;
this->inputvalue_functionmap["Content-Type"] = this->set_content_type;
this->inputvalue_functionmap["Cookie"] = this->set_cookie;
this->inputvalue_functionmap["Cross-Origin-Embedder-Policy"] = this->set_cross_origin_embedder_policy;
this->inputvalue_functionmap["Cross-Origin-Opener-Policy"] = this->set_cross_origin_opener_policy;
this->inputvalue_functionmap["Cross-Origin-Resource-Policy"] = this->set_cross_origin_resource_policy;
this->inputvalue_functionmap["Date"] = this->set_date;
this->inputvalue_functionmap["ETag"] = this->set_etag;
this->inputvalue_functionmap["Expect"] = this->set_expect;
// this->inputvalue_functionmap["Expect-CT"] = this->set_expect_ct;
this->inputvalue_functionmap["Expires"] = this->set_expires;
this->inputvalue_functionmap["Forwarded"] = this->set_forwarded;
this->inputvalue_functionmap["From"] = this->set_from;
this->inputvalue_functionmap["Host"] = this->set_host;
this->inputvalue_functionmap["If-Match"] = this->set_if_match;
this->inputvalue_functionmap["If-Modified-Since"] = this->set_if_modified_since;
this->inputvalue_functionmap["If-None-Match"] = this->set_if_none_match;
this->inputvalue_functionmap["If-Range"] = this->set_if_range;
this->inputvalue_functionmap["If-Unmodified-Since"] = this->set_if_unmodified_since;
this->inputvalue_functionmap["Keep-Alive"] = this->set_keepalive;
this->inputvalue_functionmap["Last-Modified"] = this->set_last_modified;
this->inputvalue_functionmap["Link"] = this->set_link;
this->inputvalue_functionmap["Location"] = this->set_location;
this->inputvalue_functionmap["Max-Forwards"] = this->set_max_forwards;
this->inputvalue_functionmap["Origin"] = this->set_origin;
this->inputvalue_functionmap["Permissions-Policy"] = this->set_permission_policy;
this->inputvalue_functionmap["Proxy-Authenticate"] = this->set_proxy_authenticate;
this->inputvalue_functionmap["Proxy-Authorization"] = this->set_proxy_authorization;
// this->inputvalue_functionmap["Range"] = this->set_range;
this->inputvalue_functionmap["Referer"] = this->set_referer;
this->inputvalue_functionmap["Retry-After"] = this->set_retry_after;
this->inputvalue_functionmap["Sec-Fetch-Dest"] = this->set_sec_fetch_dest;
this->inputvalue_functionmap["Sec-Fetch-Mode"] = this->set_sec_fetch_mode;
this->inputvalue_functionmap["Sec-Fetch-Site"] = this->set_sec_fetch_site;
this->inputvalue_functionmap["Sec-Fetch-User"] = this->set_sec_fetch_user;
this->inputvalue_functionmap["Sec-Purpose"] = this->set_sec_purpose;
this->inputvalue_functionmap["Sec-WebSocket-Accept"] = this->set_sec_websocket_accept;
this->inputvalue_functionmap["Server"] = this->set_server;
// this->inputvalue_functionmap["Server-Timing"] = this->set_server_timing;
this->inputvalue_functionmap["Service-Worker-Navigation-Preload"] = this->set_server_worker_navigation_preload;
this->inputvalue_functionmap["Set-Cookie"] = this->set_cookie;
this->inputvalue_functionmap["SourceMap"] = this->set_sourcemap;
this->inputvalue_functionmap["Strict-Transport-Security"] = this->set_strict_transport_security;
this->inputvalue_functionmap["TE"] = this->set_te;
this->inputvalue_functionmap["Timing-Allow-Origin"] = this->set_timing_allow_origin;
this->inputvalue_functionmap["Trailer"] = this->set_trailer;
this->inputvalue_functionmap["Transfer-Encoding"] = this->set_transfer_encoding;
this->inputvalue_functionmap["Upgrade"] = this->set_upgrade;
this->inputvalue_functionmap["Upgrade-Insecure-Requests"] = this->set_upgrade_insecure_requests;
this->inputvalue_functionmap["User-Agent"] = this->set_user_agent;
this->inputvalue_functionmap["Vary"] = this->set_vary;
this->inputvalue_functionmap["Via"] = this->set_via;
this->inputvalue_functionmap["WWW-Authenticate"] = this->set_www_authenticate;
}

std::string HttpRequest::obtain_request_key(const std::string value)
{
std::stringstream ss(value);
Expand Down Expand Up @@ -642,87 +731,128 @@ void HttpRequest::set_sec_purpose(const std::string &value)

void HttpRequest::set_sec_websocket_accept(const std::string &value)
{

this->_sec_websocket_accept = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_server(const std::string &value)
{

this->_server = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_servertiming(const std::string &value)
{
std::map<std::string, std::string> value_map;
std::stringstream ss(value);
std::string line;

std::string key;
std::getline(ss, key, ';');
while(std::getline(ss, line, ';'))
value_map[HandlingString::obtain_beforeword(HandlingString::skipping_emptyword(line), '=')] = HandlingString::obtain_afterword(HandlingString::skipping_emptyword(line), '=');
this->_servertiming.set_value(key, value_map);
}

void HttpRequest::set_service_worker_navigation_preload(const std::string &value)
{

this->_service_worker_navigation_preload = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_set_cookie(const std::string &value)
{

//valueの設定の仕方が特殊なのでちょっと考えないとピケない
}

void HttpRequest::set_sourcemap(const std::string &value)
{

this->_sourcemap = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_strict_transport_security(const std::string &value)
{

//valueの設定の仕方が特殊なのでちょっと考えないとピケない
}

void HttpRequest::set_te(const std::string &value)
{
std::stringstream ss(value);
std::string line;

while(std::getline(ss, line, ','))
{
if (line.find(';') != std::string::npos)
this->_accept.append_valueweight_set(HandlingString::skipping_emptyword(line));
else
this->_accept.append_valueweight_set(HandlingString::skipping_emptyword(line), 1.0);
}
}

void HttpRequest::set_timing_allow_origin(const std::string &value)
{

this->_timing_allow_origin = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_trailer(const std::string &value)
{

this->_trailer = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_transfer_encoding(const std::string &value)
{

std::vector<std::string> value_array;
std::stringstream ss(value);
std::string line;

while(std::getline(ss, line, ','))
value_array.push_back(HandlingString::skipping_emptyword(line));
this->_transfer_encoding.set_value_array(value_array);
}

void HttpRequest::set_upgrade(const std::string &value)
{

std::vector<std::string> value_array;
std::stringstream ss(value);
std::string line;

while(std::getline(ss, line, ','))
value_array.push_back(HandlingString::skipping_emptyword(line));
this->_upgrade.set_value_array(value_array);
}

void HttpRequest::set_upgrade_insecure_requests(const std::string &value)
{

this->_upgrade_insecure_requests = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_user_agent(const std::string &value)
{

this->_user_agent = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_vary(const std::string &value)
{

std::vector<std::string> value_array;
std::stringstream ss(value);
std::string line;

while(std::getline(ss, line, ','))
value_array.push_back(HandlingString::skipping_emptyword(line));
this->_vary.set_value_array(value_array);
}

void HttpRequest::set_via(const std::string &value)
{

this->_via = HandlingString::skipping_emptyword(value);
}

void HttpRequest::set_www_authenticate(const std::string &value)
{

std::vector<std::string> value_array;
std::stringstream ss(value);
std::string line;

while(std::getline(ss, line, ','))
value_array.push_back(HandlingString::skipping_emptyword(line));
this->_www_authenticate.set_value_array(value_array);
}

void HttpRequest::set_x_xss_protection(const std::string &value)
Expand Down
5 changes: 4 additions & 1 deletion srcs/includes/HttpRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class HttpRequest
ValueSet _te;
ValueSet _timing_allow_origin;
ValueSet _trailer;
ValueSet _transfer_encoding;
ValueArraySet _transfer_encoding;
ValueArraySet _upgrade;
ValueSet _upgrade_insecure_requests;
ValueSet _user_agent;
Expand All @@ -119,13 +119,16 @@ class HttpRequest
ValueArraySet _www_authenticate;
ValueMap _x_xss_protection;

std::map<std::string, void(*)()> inputvalue_functionmap;

HttpRequest();
HttpRequest(const HttpRequest &other);
HttpRequest &operator=(const HttpRequest &other);

bool check_keyword_exist(const std::string &key);
std::string obtain_request_key(const std::string value);
std::string obtain_request_value(const std::string value);
void ready_functionmap(void) const;

public:
HttpRequest(const std::string &value);
Expand Down

0 comments on commit 4283424

Please sign in to comment.