changed: when there is reqtype:json parameter and there is not set request.ajax_serializer

then we are using a generic json serializer
changed: we are sending the application/json header when returning an json string
added:   to config: log_server_answer (default false)
         when true we put the whole string (server's answer) to the log file
added:   to Request: use_200_status_for_not_found_and_permission_denied
         if this is true then if the server http code would be 403 or 404
         then we return 200 OK (useful when using ajax)
changed: System::RedirectTo() methods take as the last parameter: use_reqtype
         if this is true (default) then reqtype:type parameter is automatically added to the redirecting path
         




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@918 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2013-03-26 00:04:01 +00:00
parent be6e09c5af
commit 8d9a021eab
13 changed files with 152 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2013, Tomasz Sowa
* All rights reserved.
*
*/
@@ -438,6 +438,7 @@ bool sent = false;
if( cur.request->ajax_serializer )
{
log << log3 << "App: sending JSON" << logend;
std::wstring & ajax_content = cur.request->ajax.Add(L"content", L"");
ajax_content = cur.request->page.Str();
cur.request->ajax_serializer->Serialize(cur.request->ajax, cur.request->ajaxpage, true);
@@ -524,6 +525,13 @@ void App::Make()
return;
}
if( !cur.request->ajax_serializer && cur.request->ParamValue(L"reqtype") == L"json")
{
log << log3 << "App: using generic JSON serializer" << logend;
ajax_generic_serializer.Clear();
cur.request->ajax_serializer = &ajax_generic_serializer;
}
plugin.Call(WINIX_CONTENT_MAKE);
MakePage();
@@ -801,21 +809,29 @@ void App::SendHeadersStatic()
}
void App::SendHeaderContentType()
{
switch( config.content_type_header )
if( cur.request->ajax_serializer )
{
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;
FCGX_PutS("Content-Type: application/json", fcgi_request.out);
}
else
{
switch( config.content_type_header )
{
case 1:
FCGX_PutS("Content-Type: application/xhtml+xml", fcgi_request.out);
break;
case 0:
default:
FCGX_PutS("Content-Type: text/html", fcgi_request.out);
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 )
@@ -830,7 +846,6 @@ void App::SendHeadersForbidden()
{
FCGX_PutS("Status: 403 Forbidden\r\n", fcgi_request.out);
SendHeaderContentType();
log << log2 << "App: response: 403 Forbidden" << logend;
}
@@ -893,7 +908,6 @@ void App::SendHeadersNormal(Header header)
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out);
SendHeaderContentType();
log << log2 << "App: response: 404 Not Found" << logend;
break;
case h_403:
@@ -971,6 +985,9 @@ void App::FilterCompressSend(bool compressing, int compress_encoding, const std:
else
AssignString(*source, source_a);
if( config.log_server_answer )
log << log1 << "App: the server's answer is:\n" << source_a << "\nApp: end of the server's answer" << logend;
if( compressing )
compress.CompressAndPut(source_a.c_str(), source_a.length(), fcgi_request.out, compress_encoding);
else
@@ -1089,10 +1106,22 @@ int compress_encoding;
SelectCompression(source->length(), compressing, compress_encoding);
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
{
header = h_404;
log << log2 << "App: http response: 404 Not Found" << logend;
}
if( status == WINIX_ERR_PERMISSION_DENIED || status == WINIX_ERR_CANT_CHANGE_USER || status == WINIX_ERR_CANT_CHANGE_GROUP )
{
header = h_403;
log << log2 << "App: http response: 403 Forbidden" << logend;
}
if( cur.request->use_200_status_for_not_found_and_permission_denied && (header == h_404 || header == h_403) )
{
log << log3 << "App: changing the http response to: 200 OK" << logend;
header = h_200;
}
SendHeaders(compressing, compress_encoding, header);
@@ -1114,24 +1143,13 @@ void App::SendData(const BinaryPage & page, FCGX_Stream * out)
BinaryPage::const_iterator i = page.begin();
BinaryPage::const_iterator end = page.end();
// log << log1 << "size: " << page.size() << logend;
// for(size_t x=0 ; x<page.size() ; ++x)
// log << int((unsigned char)page[x]) << ' ';
// log << logend;
while( i != end )
{
size_t s = 0;
for( ; i != end && s < buf_size ; ++i, ++s)
{
send_data_buf[s] = *i;
// log << "swinka: " << int((unsigned char)*i) << logend;
}
if( s > 0 )
FCGX_PutStr(send_data_buf.c_str(), s, fcgi_request.out);
}