removed: Request::debug all stream used for debugging info

some environment variables were put there
removed: config variable: debug_info
removed: Request::role (responder, authorizer)
         now we have only one role: responder
added:   new config variables:
         log_env_variables (default false) - when true then fastcgi environment
         variables are logged to the log file
         log_http_answer_headers (default false) - when true all http headers
         created by winix ale logged (note that the www server can add/adjust other headers)
changed: some refactoring in Request struct
changed: CookieTab to std::map<std::wstring, std::wstring>
         beforehand std::string was used
         (changed CookieParser as well)
changed: Request::SetCookie() to AddCookie()
added:   Request::out_headers (a PT::Space struct)
         http headers (without cookies) send back to the client
added:   Request::out_cookies (a PT::Space struct)
         cookies send to the client
changed: App class to use Request::out_headers and Request::out_cookies
         some SendHeaders...() methods were renamed to PrepareHeaders...()
         and they create output in Request::out_headers first (and out_cookies)
         and later it is sent
added:   two plugin messages:
         // http headers (without cookies) were created and are ready to send
         // here you can make some changes to them
         // in p1 you have a pointer to the PT::Space (Request::out_headers)
         #define WINIX_PREPARE_TO_SEND_HTTP_HEADERS		31070

         // http cookies were created and are ready to send
         // here you can make some changes to them
         // in p1 you have a pointer to the PT::Space (Request::out_cookies)
         #define WINIX_PREPARE_TO_SEND_HTTP_COOKIES		31080
added:   config variable:
         // how many output streams do we have in Request class
         // default: 16 (64 maximum)
         size_t ezc_out_streams_size;




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@940 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2013-11-29 21:39:23 +00:00
parent 3e32f3784f
commit 375604edd6
11 changed files with 419 additions and 302 deletions

View File

@@ -22,6 +22,7 @@
#include "date/date.h"
#include "space/space.h"
#include "space/spacetojson.h"
#include "textstream/textstream.h"
@@ -32,23 +33,164 @@ class FunctionBase;
struct Request
{
// request id
// is incremented for each request and is never 0
// (from -1 will be incremented twice)
// it's used for some optimalizations e.g. in templates
/*
request id
is incremented for each request and is never 0
(from -1 will be incremented to one)
it's used for some optimizations e.g. in templates
*/
size_t id;
// !! moze pozbyc sie tego none?
enum Method { get, post, head, none } method;
enum Role { responder, authorizer } role;
// headers, page and debug
//std::ostringstream headers, page, debug;
// !! IMPROVE ME change headers to some kind of a map, may PT::Space ?
TextStream<std::string> headers;
HtmlTextStream debug;
/*
request start time
Time() methods are very slow so it is better to directly use those two values
they are set when a request starts
*/
time_t start_time;
PT::Date start_date;
/*
*
*
*
* variables representing input from client's browser
*
*
*
*/
/*
the HTTP method
!! IMPROVE ME add the rest methods here
*/
enum Method { get, post, head, unknown_method } method;
/*
subdomain
subdomain = HTTP_HOST environment variable - config->base_url
*/
std::wstring subdomain;
/*
raw parameters
!! CHECK ME may post_tab and cookie_tab should be changed to PT::Space now?
or may change the name to cookie_in? or in_cookie?
*/
PostTab post_tab;
PostFileTab post_file_tab;
CookieTab cookie_tab;
/*
html anchor (those part of URI after '#' character)
*/
std::wstring anchor;
// environment variables
// they are not null -- when the server doesn't have such a variable
// it will be pointing into 'char_empty' which is default '\0'
// !! IMPROVE ME change it to std::wstring, or may PT::Space too?
const char * env_request_method;
const char * env_request_uri;
const char * env_http_cookie;
const char * env_remote_addr;
const char * env_http_host;
const char * env_http_user_agent;
const char * env_http_accept_encoding;
const char * env_fcgi_role;
const char * env_content_type;
const char * env_https;
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
// (at the moment only IPv4 are supported)
int ip;
// true if the browser is Microsoft Internet Explorer
bool browser_msie;
// true if the browser is Konqueror
bool browser_konqueror;
// true if we are using an encrypted connection (SSL)
bool using_ssl;
/*
request input variables representing the winix filesystem
*/
// current directory
std::vector<Item*> dir_tab;
// true if a file exists
bool is_item;
// current file (valid if is_item is true)
Item item;
// current winix function
// null if there is no a function
FunctionBase * function;
// parameters (name:value)
// !! CHECK ME may it should be changed to PT::Space?
ParamTab param_tab;
// this is a pointer either to the item (if exists) or to the last directory
Item * last_item;
/*
*
*
*
* variables for generating output to the client's browser
*
*
*
*/
// request status
// !! CHANGE ME it'll be better to use ordinary http result codes
Error status;
// if not empty means an address for redirecting to
// it should be url-encoded
std::wstring redirect_to;
// a redirect type
// following redirect types are supported:
// 300 Multiple Choices
// 301 Moved Permanently
// 302 Found
// 303 See Other (default)
// 307 Temporary Redirect
int redirect_type;
// send header X-LIGHTTPD-send-file with path to a file
std::wstring x_sendfile;
// send as attachment (causes generating header: content-disposition: attachment)
bool send_as_attachment;
// headers send to the client (without cookies)
PT::Space out_headers;
// cookies send to the client
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
PT::Space out_cookies;
// winix can return either a text answer or a binary answer
// if send_bin_stream is true then the binary answer is sent (out_bin_stream)
// or if send_bin_stream is false then the text answer is sent
@@ -147,100 +289,7 @@ struct Request
// default: true
bool use_html_filter;
// raw parameters
PostTab post_tab;
PostFileTab post_file_tab;
CookieTab cookie_tab;
// html anchor (those part of URI after '#' character)
std::wstring anchor;
// environment variables
// they are not null -- when the server doesn't have such a variable
// it will be pointing into 'char_empty' which is default '\0'
const char * env_request_method;
const char * env_request_uri;
const char * env_http_cookie;
const char * env_remote_addr;
const char * env_http_host;
const char * env_http_user_agent;
const char * env_http_accept_encoding;
const char * env_fcgi_role;
const char * env_content_type;
const char * env_https;
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
// (at the moment only IPv4 are supported)
int ip;
// true if the browser is Microsoft Internet Explorer
bool browser_msie;
// true if the browser is Konqueror
bool browser_konqueror;
// true if we are using encrypted connection (SSL)
bool using_ssl;
// current directory
std::vector<Item*> dir_tab;
// true if a file exists
bool is_item;
// current file (if exists)
Item item;
// current winix function
// null if there is no a function
FunctionBase * function;
// parameters (name:value)
ParamTab param_tab;
// request status
Error status;
// usually items in the current directory (depends on the function)
std::vector<Item> item_tab;
// if not empty means an address for redirecting to
// it should be url-encoded
std::wstring redirect_to;
std::string aredirect_to;
// a redirect type
// following redirect types are supported:
// 300 Multiple Choices
// 301 Moved Permanently
// 302 Found
// 303 See Other (default)
// 307 Temporary Redirect
int redirect_type;
// send header X-LIGHTTPD-send-file with path to a file
std::wstring x_sendfile;
// send as attachment (causes header: content-disposition: attachment)
bool send_as_attachment;
// this is a pointer either to the item (if exists) or to the last directory
Item * last_item;
// request start time
// Time() methods are very slow so it is better to directly use those two values
// they are set when a request starts
time_t start_time;
PT::Date start_date;
// a subdomain
// subdomain = HTTP_HOST environment variable - config->base_url
std::wstring subdomain;
// if this variable is true then winix always return 200 OK header
// when the status would be 404 (not found) or 403 (permission denied)
// default: false
@@ -252,6 +301,24 @@ struct Request
bool gen_use_special_chars;
/*
additional variables used for common uses
*/
// usually items in the current directory (depends on the function)
std::vector<Item> item_tab;
Request();
void SetConfig(Config * pconfig);
void RequestStarts();
@@ -261,29 +328,32 @@ struct Request
bool IsParam(const wchar_t * param_name);
bool IsParam(const std::wstring & param_name);
const std::wstring & ParamValue(const wchar_t * param_name); // returns an empty string if there is no such a parameter
const std::wstring & ParamValue(const std::wstring & param_name); // returns an empty string if there is no such a parameter
void SetCookie(const char * name, const char * value, PT::Date * expires = 0);
void SetCookie(const char * name, long value, PT::Date * expires = 0);
bool IsPostVar(const wchar_t * var);
bool IsPostVar(const std::wstring & var);
const std::wstring & PostVar(const wchar_t * var); // returns an empty string if there is no such a parameter
const std::wstring & PostVar(const std::wstring & var); // returns an empty string if there is no such a parameter
bool PostVar(const wchar_t * var, std::wstring & result);
bool PostVar(const std::wstring & var, std::wstring & result);
std::wstring * PostVarp(const wchar_t * var);
std::wstring * PostVarp(const std::wstring & var);
bool AllPostVarEmpty(); // returning true if all post vars are empty
void SendAll();
// setting a cookie
// name - cookie name (either const wchar_t, or std::wstring or PT::WTextStream)
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
template<typename NameType, typename ValueType>
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
template<typename NameType, typename ValueType>
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
private:
@@ -303,8 +373,42 @@ private:
template<typename NameType, typename ValueType>
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
{
PT::WTextStream cookie;
cookie << value;
if( cookie.empty() )
cookie << L"\"\""; // cookie empty value
if( expires )
cookie << L"; expires=" << DateToStrCookie(*expires) << L" GMT";
cookie << L"; path=/; domain=" << config->base_url;
/*
!! IMPROVE ME add an option to the config
don't use '; secure' flag if you are using both sites (with SSL
and without SSL) -- with secure flag the cookie is sent only through
SSL and if you accidentally open a new window without SSL (http://)
then winix will create a new session for you and the previous session (https://)
will be lost (the session cookie will be overwritten in the client's browser)
*/
return out_cookies.Add(name, cookie);
}
template<typename NameType, typename ValueType>
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
{
return AddCookie(name, value, &expires);
}
#endif