added: to config: 'content_type_header' parameter

the kind of "Content-Type" header send to the client
       if utf8 is enabled then 'charset=UTF-8' will also be appended
added: to templates: an index pattern for 'rawcontent'
       used when 'rawcontent' parameter is present
       by default the template has only one [content] ezc function
       useful in AJAX requests       


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@784 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-12-17 21:59:22 +00:00
parent fe2f1605f1
commit fa05e25a9d
6 changed files with 92 additions and 22 deletions

View File

@ -667,12 +667,35 @@ void App::SendHeadersStatic()
} }
void App::SendHeaderContentType()
{
switch( config.content_type_header )
{
case 1:
FCGX_PutS("Content-Type: application/xhtml+xml", fcgi_request.out);
break;
case 2:
FCGX_PutS("Content-Type: application/xml", fcgi_request.out);
break;
case 0:
default:
FCGX_PutS("Content-Type: text/html", fcgi_request.out);
}
if( config.utf8 )
FCGX_PutS("; charset=UTF-8", fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);
}
void App::SendHeadersForbidden() void App::SendHeadersForbidden()
{ {
FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out); FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); SendHeaderContentType();
log << log2 << "App: response: 403 Forbidden" << logend; log << log2 << "App: response: 403 Forbidden" << logend;
} }
@ -739,7 +762,7 @@ void App::SendHeadersNormal(Header header)
{ {
case h_404: case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out); FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); SendHeaderContentType();
log << log2 << "App: response: 404 Not Found" << logend; log << log2 << "App: response: 404 Not Found" << logend;
break; break;
@ -751,7 +774,7 @@ void App::SendHeadersNormal(Header header)
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out); FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
if( cur.request->role != Request::authorizer ) if( cur.request->role != Request::authorizer )
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out); SendHeaderContentType();
} }
} }

View File

@ -152,6 +152,7 @@ private:
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref); void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
bool SendHeadersStaticCreateResource(); bool SendHeadersStaticCreateResource();
void SendHeadersStatic(); void SendHeadersStatic();
void SendHeaderContentType();
void SendHeadersForbidden(); void SendHeadersForbidden();
void SendHeadersRedirect(); void SendHeadersRedirect();
void SendHeadersSendFile(); void SendHeadersSendFile();

View File

@ -227,6 +227,8 @@ void Config::AssignValues(bool stdout_is_closed)
pattern_cacher_when_delete = Size(L"pattern_cacher_when_delete", 130); pattern_cacher_when_delete = Size(L"pattern_cacher_when_delete", 130);
pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30); pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30);
content_type_header = Int(L"content_type_header", 0);
} }
@ -245,6 +247,9 @@ void Config::SetAdditionalVariables()
CheckLocale(); CheckLocale();
CheckPasswd(); CheckPasswd();
if( content_type_header < 0 || content_type_header > 2 )
content_type_header = 0;
} }

View File

@ -445,8 +445,13 @@ public:
size_t pattern_cacher_when_delete; size_t pattern_cacher_when_delete;
size_t pattern_cacher_how_many_delete; size_t pattern_cacher_how_many_delete;
// header "Content-Type" send to the client
// 0 - text/html - for HTML
// 1 - application/xhtml+xml - for XHTML 1.0
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
// default: 0
// if utf8 is true then "; charset=UTF-8" will also be appended
int content_type_header;

View File

@ -19,7 +19,8 @@ namespace TemplatesFunctions
{ {
size_t pat_index; // main index pattern size_t pat_index; // main index pattern
size_t pat_index_fullscreen; // an empty pattern (without menus etc., used for ckeditor images browser) size_t pat_index_fullscreen; // an empty pattern (without menus etc. but with all rest html tags, used for ckeditor images browser)
size_t pat_index_rawcontent; // completly empty pattern (only content, without html tags such as <html>, <body>)
size_t pat_err_404; // 404 error size_t pat_err_404; // 404 error
size_t pat_err_per_denied; // permission denied error size_t pat_err_per_denied; // permission denied error
@ -695,6 +696,7 @@ using namespace TemplatesFunctions;
pat_index = patterns.Add(config->templates_index); pat_index = patterns.Add(config->templates_index);
pat_index_fullscreen = patterns.Add(L"index_fullscreen.html"); pat_index_fullscreen = patterns.Add(L"index_fullscreen.html");
pat_index_rawcontent = patterns.Add(L"index_rawcontent.html");
pat_err_404 = patterns.Add(L"err_404.html"); pat_err_404 = patterns.Add(L"err_404.html");
pat_err_per_denied = patterns.Add(L"err_per_denied.html"); pat_err_per_denied = patterns.Add(L"err_per_denied.html");
@ -741,34 +743,53 @@ using namespace TemplatesFunctions;
} }
void Templates::Generate()
// can return a null pointer
Ezc::Pattern * Templates::SelectIndexPatternFromItemAndMountPoint()
{ {
using namespace TemplatesFunctions; using namespace TemplatesFunctions;
Ezc::Pattern * index = 0; Ezc::Pattern * index = 0;
const std::wstring * index_file_local = 0; const std::wstring * index_file_local = 0;
if( cur->request->IsParam(L"fullscreen") ) // first we try to get an index template from 'template' item parameter (template winix function)
// if such a parameter is not defined then we try to get an index from the mount point
if( !cur->request->last_item->html_template.empty() )
{ {
index = patterns.Get(pat_index_fullscreen, locale.GetLang()); index_file_local = &cur->request->last_item->html_template;
} }
else else
{ {
if( !cur->request->last_item->html_template.empty() ) Mounts & mounts = TemplatesFunctions::system->mounts;
index_file_local = &cur->request->last_item->html_template; const std::wstring & temp = cur->mount->FirstArg(mounts.MountParHtmlTemplate());
if( !index_file_local ) if( !temp.empty() )
{ index_file_local = &temp;
Mounts & mounts = TemplatesFunctions::system->mounts;
const std::wstring & temp = cur->mount->FirstArg(mounts.MountParHtmlTemplate());
if( !temp.empty() )
index_file_local = &temp;
}
if( index_file_local && *index_file_local != config->templates_index )
index = index_patterns.Get(*index_file_local, locale.GetLang());
} }
if( index_file_local && *index_file_local != config->templates_index )
index = index_patterns.Get(*index_file_local, locale.GetLang());
return index;
}
// can return a null pointer
Ezc::Pattern * Templates::SelectIndexPattern()
{
using namespace TemplatesFunctions;
Ezc::Pattern * index = 0;
if( cur->request->IsParam(L"rawcontent") )
index = patterns.Get(pat_index_rawcontent, locale.GetLang());
else
if( cur->request->IsParam(L"fullscreen") )
index = patterns.Get(pat_index_fullscreen, locale.GetLang());
else
index = SelectIndexPatternFromItemAndMountPoint();
if( !index ) if( !index )
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetLang()); index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetLang());
@ -776,6 +797,17 @@ using namespace TemplatesFunctions;
if( !index ) if( !index )
index = patterns.Get(pat_index, locale.GetLang());; index = patterns.Get(pat_index, locale.GetLang());;
return index;
}
void Templates::Generate()
{
using namespace TemplatesFunctions;
Ezc::Pattern * index = SelectIndexPattern();
if( index ) if( index )
generator.Generate(cur->request->page, *index); generator.Generate(cur->request->page, *index);
else else

View File

@ -37,6 +37,8 @@ class Functions;
namespace TemplatesFunctions namespace TemplatesFunctions
{ {
extern size_t pat_index; extern size_t pat_index;
extern size_t pat_index_fullscreen;
extern size_t pat_index_rawcontent;
extern size_t pat_err_404; extern size_t pat_err_404;
extern size_t pat_err_per_denied; extern size_t pat_err_per_denied;
@ -485,6 +487,8 @@ private:
void ReadLocale(); void ReadLocale();
void SetHtmlFilter(); void SetHtmlFilter();
void CreateFunctions(); // should be called before reading patterns (patterns will cache ezc functions) void CreateFunctions(); // should be called before reading patterns (patterns will cache ezc functions)
Ezc::Pattern * SelectIndexPatternFromItemAndMountPoint();
Ezc::Pattern * SelectIndexPattern();
TemplatesFunctions::EzcGen generator; TemplatesFunctions::EzcGen generator;
std::wstring temp; std::wstring temp;