move some methods from App to Request
methods moved: SetEnv(), ReadEnvVariables(), ReadEnvRemoteIP(), CheckSSL(), SetSubdomain() while here: - add the rest of http methods: put, connect, trace, patch
This commit is contained in:
@@ -34,13 +34,13 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/un.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <utility>
|
||||
#include <fastcgi.h>
|
||||
#include <stddef.h>
|
||||
@@ -1109,11 +1109,11 @@ void App::ParseAcceptLanguageHeader()
|
||||
*/
|
||||
void App::ReadRequest()
|
||||
{
|
||||
ReadEnvVariables();
|
||||
ReadEnvRemoteIP();
|
||||
CheckRequestMethod();
|
||||
CheckSSL();
|
||||
SetSubdomain();
|
||||
cur.request->ReadEnvVariables();
|
||||
cur.request->ReadEnvRemoteIP();
|
||||
cur.request->CheckRequestMethod();
|
||||
cur.request->CheckSSL();
|
||||
cur.request->SetSubdomain();
|
||||
|
||||
LogAccess();
|
||||
ReadEnvHTTPVariables();
|
||||
@@ -1145,35 +1145,6 @@ void App::ReadRequest()
|
||||
}
|
||||
|
||||
|
||||
void App::SetEnv(const char * name, std::wstring & env)
|
||||
{
|
||||
const char * v = FCGX_GetParam(name, cur.request->fcgi_request.envp);
|
||||
|
||||
if( v )
|
||||
{
|
||||
pt::utf8_to_wide(v, env);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME take it from cur.request.headers_in?
|
||||
*/
|
||||
void App::ReadEnvVariables()
|
||||
{
|
||||
SetEnv("REQUEST_METHOD", cur.request->env_request_method);
|
||||
SetEnv("REQUEST_URI", cur.request->env_request_uri);
|
||||
SetEnv("FCGI_ROLE", cur.request->env_fcgi_role);
|
||||
SetEnv("CONTENT_TYPE", cur.request->env_content_type);
|
||||
SetEnv("HTTPS", cur.request->env_https);
|
||||
|
||||
SetEnv("HTTP_HOST", cur.request->env_http_host);
|
||||
SetEnv("HTTP_USER_AGENT", cur.request->env_http_user_agent);
|
||||
SetEnv("HTTP_COOKIE", cur.request->env_http_cookie);
|
||||
SetEnv("HTTP_ACCEPT_ENCODING", cur.request->env_http_accept_encoding);
|
||||
SetEnv("HTTP_ACCEPT", cur.request->env_http_accept);
|
||||
SetEnv("HTTP_ACCEPT_LANGUAGE", cur.request->env_http_accept_language);
|
||||
}
|
||||
|
||||
|
||||
// reading from fastcgi env
|
||||
@@ -1262,69 +1233,6 @@ bool App::SaveEnvHTTPVariable(const char * env)
|
||||
}
|
||||
|
||||
|
||||
void App::ReadEnvRemoteIP()
|
||||
{
|
||||
const char * v = nullptr;
|
||||
|
||||
if( config.check_proxy_ip_header )
|
||||
{
|
||||
http_header_name = L"HTTP_";
|
||||
http_header_name += config.proxy_ip_header;
|
||||
pt::to_upper_emplace(http_header_name);
|
||||
|
||||
pt::wide_to_utf8(http_header_name, http_header_8bit);
|
||||
v = FCGX_GetParam(http_header_8bit.c_str(), cur.request->fcgi_request.envp);
|
||||
}
|
||||
else
|
||||
{
|
||||
v = FCGX_GetParam("REMOTE_ADDR", cur.request->fcgi_request.envp);
|
||||
}
|
||||
|
||||
if( v )
|
||||
{
|
||||
cur.request->ip = (int)inet_addr(v);
|
||||
pt::utf8_to_wide(v, cur.request->ip_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void App::CheckRequestMethod()
|
||||
{
|
||||
cur.request->method = Request::unknown_method;
|
||||
|
||||
if( !cur.request->env_request_method.empty() )
|
||||
{
|
||||
if( pt::to_lower(cur.request->env_request_method[0]) == 'g' )
|
||||
cur.request->method = Request::get;
|
||||
else
|
||||
if( pt::to_lower(cur.request->env_request_method[0]) == 'p' )
|
||||
cur.request->method = Request::post;
|
||||
else
|
||||
if( pt::to_lower(cur.request->env_request_method[0]) == 'h' )
|
||||
cur.request->method = Request::head;
|
||||
else
|
||||
if( pt::to_lower(cur.request->env_request_method[0]) == 'd' )
|
||||
cur.request->method = Request::delete_;
|
||||
else
|
||||
if( pt::to_lower(cur.request->env_request_method[0]) == 'o' )
|
||||
cur.request->method = Request::options;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void App::CheckSSL()
|
||||
{
|
||||
// !! CHECK ME
|
||||
// value "on" exists in lighttpd server
|
||||
// make sure that for other servers is "on" too
|
||||
|
||||
if( config.assume_connection_is_through_ssl )
|
||||
cur.request->using_ssl = true;
|
||||
else
|
||||
if( pt::is_equal_nc(cur.request->env_https.c_str(), L"on") )
|
||||
cur.request->using_ssl = true;
|
||||
}
|
||||
|
||||
|
||||
void App::CheckHtmx()
|
||||
{
|
||||
@@ -1338,12 +1246,6 @@ void App::CheckHtmx()
|
||||
}
|
||||
|
||||
|
||||
void App::SetSubdomain()
|
||||
{
|
||||
CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host.c_str(), cur.request->subdomain);
|
||||
}
|
||||
|
||||
|
||||
void App::LogAccess()
|
||||
{
|
||||
log << log1;
|
||||
|
Reference in New Issue
Block a user