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;
|
||||
|
||||
@@ -142,7 +142,6 @@ private:
|
||||
|
||||
std::wstring http_header_name;
|
||||
std::wstring http_header_value;
|
||||
std::string http_header_8bit;
|
||||
pt::WTextStream empty_response;
|
||||
|
||||
WinixModelConnector model_connector; // main thread model connector, each thread has its own connector
|
||||
@@ -198,17 +197,13 @@ private:
|
||||
void ReadEnvVariables();
|
||||
void ReadEnvHTTPVariables();
|
||||
bool SaveEnvHTTPVariable(const char * env);
|
||||
void ReadEnvRemoteIP();
|
||||
void ReadInputPostToBuffer();
|
||||
void ParsePostJson();
|
||||
void ReadPostJson();
|
||||
void ReadPostVars();
|
||||
void CheckIE();
|
||||
void CheckKonqueror();
|
||||
void CheckRequestMethod();
|
||||
void CheckSSL();
|
||||
void CheckHtmx();
|
||||
void SetSubdomain();
|
||||
bool IsRequestedFrame();
|
||||
void SendHeaders();
|
||||
void SendCookies();
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
@@ -245,7 +249,7 @@ void Request::Clear()
|
||||
aheader_value.clear();
|
||||
cookie_id_string.clear();
|
||||
send_data_buf.clear();
|
||||
|
||||
http_header_name.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -1944,6 +1948,179 @@ void Request::LogRequestTime()
|
||||
}
|
||||
|
||||
|
||||
void Request::SetEnv(const char * name, std::wstring & env)
|
||||
{
|
||||
const char * v = FCGX_GetParam(name, fcgi_request.envp);
|
||||
|
||||
if( v )
|
||||
{
|
||||
pt::utf8_to_wide(v, env);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME take it from cur.request.headers_in?
|
||||
*/
|
||||
void Request::ReadEnvVariables()
|
||||
{
|
||||
SetEnv("REQUEST_METHOD", env_request_method);
|
||||
SetEnv("REQUEST_URI", env_request_uri);
|
||||
SetEnv("FCGI_ROLE", env_fcgi_role);
|
||||
SetEnv("CONTENT_TYPE", env_content_type);
|
||||
SetEnv("HTTPS", env_https);
|
||||
|
||||
SetEnv("HTTP_HOST", env_http_host);
|
||||
SetEnv("HTTP_USER_AGENT", env_http_user_agent);
|
||||
SetEnv("HTTP_COOKIE", env_http_cookie);
|
||||
SetEnv("HTTP_ACCEPT_ENCODING", env_http_accept_encoding);
|
||||
SetEnv("HTTP_ACCEPT", env_http_accept);
|
||||
SetEnv("HTTP_ACCEPT_LANGUAGE", env_http_accept_language);
|
||||
}
|
||||
|
||||
|
||||
void Request::ReadEnvRemoteIP()
|
||||
{
|
||||
const char * v = nullptr;
|
||||
|
||||
if( config && config->check_proxy_ip_header )
|
||||
{
|
||||
http_header_8bit = "HTTP_";
|
||||
pt::wide_to_utf8(config->proxy_ip_header, http_header_8bit, false);
|
||||
pt::to_upper_emplace(http_header_8bit);
|
||||
v = FCGX_GetParam(http_header_8bit.c_str(), fcgi_request.envp);
|
||||
}
|
||||
else
|
||||
{
|
||||
v = FCGX_GetParam("REMOTE_ADDR", fcgi_request.envp);
|
||||
}
|
||||
|
||||
if( v )
|
||||
{
|
||||
ip = (int)inet_addr(v);
|
||||
pt::utf8_to_wide(v, ip_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Request::Method Request::CheckRequestMethod(const wchar_t * name)
|
||||
{
|
||||
Method method = Request::unknown_method;
|
||||
|
||||
if( pt::is_equal_nc(name, L"GET") )
|
||||
method = Request::get;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"HEAD") )
|
||||
method = Request::head;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"POST") )
|
||||
method = Request::post;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"PUT") )
|
||||
method = Request::put;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"DELETE") )
|
||||
method = Request::delete_;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"CONNECT") )
|
||||
method = Request::connect;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"OPTIONS") )
|
||||
method = Request::options;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"TRACE") )
|
||||
method = Request::trace;
|
||||
else
|
||||
if( pt::is_equal_nc(name, L"PATCH") )
|
||||
method = Request::patch;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
void Request::CheckRequestMethod()
|
||||
{
|
||||
method = CheckRequestMethod(env_request_method.c_str());
|
||||
}
|
||||
|
||||
|
||||
void Request::CheckSSL()
|
||||
{
|
||||
// !! CHECK ME
|
||||
// value "on" exists in lighttpd server
|
||||
// make sure that for other servers is "on" too
|
||||
|
||||
if( config && config->assume_connection_is_through_ssl )
|
||||
using_ssl = true;
|
||||
else
|
||||
if( pt::is_equal_nc(env_https.c_str(), L"on") )
|
||||
using_ssl = true;
|
||||
}
|
||||
|
||||
|
||||
void Request::SetSubdomain()
|
||||
{
|
||||
if( config )
|
||||
{
|
||||
CreateSubdomain(config->base_url.c_str(), env_http_host.c_str(), subdomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::PutMethodName(Request::Method method, pt::Stream & stream)
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
case get:
|
||||
stream << L"GET";
|
||||
break;
|
||||
|
||||
case head:
|
||||
stream << L"HEAD";
|
||||
break;
|
||||
|
||||
case post:
|
||||
stream << L"POST";
|
||||
break;
|
||||
|
||||
case put:
|
||||
stream << L"PUT";
|
||||
break;
|
||||
|
||||
case delete_:
|
||||
stream << L"DELETE";
|
||||
break;
|
||||
|
||||
case connect:
|
||||
stream << L"CONNECT";
|
||||
break;
|
||||
|
||||
case options:
|
||||
stream << L"OPTIONS";
|
||||
break;
|
||||
|
||||
case trace:
|
||||
stream << L"TRACE";
|
||||
break;
|
||||
|
||||
case patch:
|
||||
stream << L"PATCH";
|
||||
break;
|
||||
|
||||
default:
|
||||
stream << L"UNKNOWN";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Request::PutMethodName(pt::Stream & stream)
|
||||
{
|
||||
PutMethodName(method, stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::FinishRequest()
|
||||
{
|
||||
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
the HTTP method
|
||||
!! IMPROVE ME add the rest methods here
|
||||
*/
|
||||
enum Method { get, post, head, delete_, options, unknown_method } method;
|
||||
enum Method { get, head, post, put, delete_, connect, options, trace, patch, unknown_method } method;
|
||||
|
||||
|
||||
/*
|
||||
@@ -519,6 +519,20 @@ public:
|
||||
|
||||
void FinishRequest();
|
||||
|
||||
|
||||
void SetEnv(const char * name, std::wstring & env);
|
||||
void ReadEnvVariables();
|
||||
void ReadEnvRemoteIP();
|
||||
|
||||
static Method CheckRequestMethod(const wchar_t * name);
|
||||
void CheckRequestMethod();
|
||||
|
||||
void CheckSSL();
|
||||
void SetSubdomain();
|
||||
|
||||
static void PutMethodName(Request::Method method, pt::Stream & stream);
|
||||
void PutMethodName(pt::Stream & stream);
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
@@ -534,6 +548,8 @@ private:
|
||||
std::string aheader_name, aheader_value;
|
||||
std::wstring cookie_id_string;
|
||||
std::string send_data_buf;
|
||||
std::wstring http_header_name;
|
||||
std::string http_header_8bit;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user