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:
@@ -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()
|
||||
{
|
||||
|
Reference in New Issue
Block a user