added: acceptbaseparser.h acceptbaseparser.cpp

class AcceptBaseParser for parsing http accept* headers
added: acceptencodingparser.h
       class AcceptEncodingParser for parsing HTTP_ACCEPT_ENCODING header
added: compresion only when HTTP_ACCEPT_ENCODING has 'deflate'
       and the browser is not the Internet Explorer


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@515 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-10-08 17:59:10 +00:00
parent 85b678a8fb
commit 7db71d43e0
11 changed files with 527 additions and 249 deletions

View File

@@ -51,7 +51,8 @@ void Request::Clear()
env_http_cookie = &char_empty;
env_remote_addr = &char_empty;
env_http_host = &char_empty;
env_http_user_agent = &char_empty;
env_http_accept_encoding = &char_empty;
session = 0;
@@ -79,6 +80,7 @@ void Request::Clear()
notify_code = 0;
browser_msie = false;
}
@@ -248,6 +250,19 @@ void Request::ReadEnvVariables()
env_remote_addr = SetEnvVar("REMOTE_ADDR");
env_http_host = SetEnvVar("HTTP_HOST");
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
env_http_accept_encoding = SetEnvVar("HTTP_ACCEPT_ENCODING");
}
void Request::CheckIE()
{
char * msie = strstr(env_http_user_agent, "MSIE");
if( msie )
browser_msie = true;
else
browser_msie = false;
}
@@ -266,12 +281,8 @@ void Request::CheckMethod()
void Request::ReadParameters()
{
// !!some parameters (get) we have always
// if( method == get )
{
GetParser get_parser(env_request_uri, get_table);
get_parser.Parse();
}
GetParser get_parser(env_request_uri, get_table);
get_parser.Parse();
if( method == post )
{
@@ -281,6 +292,8 @@ void Request::ReadParameters()
CookieParser cookie_parser(env_http_cookie, cookie_table);
cookie_parser.Parse();
accept_encoding_parser.Parse(env_http_accept_encoding);
}
@@ -300,6 +313,7 @@ void Request::Read()
StandardLog();
CheckMethod();
ReadParameters();
CheckIE();
}
@@ -319,7 +333,9 @@ void Request::SendAll()
FCGX_PutS("Content-Type: Text/Html\r\n", out);
}
if( data.compression )
bool compressing = data.compression && !browser_msie && accept_encoding_parser.AcceptDeflate();
if( compressing )
FCGX_PutS("Content-Encoding: deflate\r\n", out);
FCGX_PutS(headers.str().c_str(), out);
@@ -333,11 +349,15 @@ void Request::SendAll()
const std::string & source = page.str();
if( !data.compression || compress.CompressAndPut(source.c_str(), source.length(), out) != 0 )
if( compressing )
{
compress.CompressAndPut(source.c_str(), source.length(), out);
}
else
{
// there were problems during compressing, or we don't use compression at all
FCGX_PutS(source.c_str(), out);
}
const std::string & d = debug.str();