removed: ezn patterns for rawcontent and ajaxcontent:
index_rawcontent.html, index_ajaxcontent.html now we have out_streams in Request and some special keyword in ezc templates for sending content to the specified streams changed: the way how winix answers to the client's browsers: info from Request class: winix answer send to the client's browser | | depending on send_bin_stream ------------------------------------------------- | | text answer binary answer | | depending on return_json sending out_bin_stream ------------------------------------ | | normal request ajax request | | sending out_streams[0] depending on return_info_only ------------------------------------------------------ | | generating JSON object from: generating JSON object only from info out_streams and info, e.g.: e.g.: { { info object serialized here } "stream_1": "some html content", "stream_2": "some other html content", "info": { info object serialized here } } note that out_streams[0] is not sent in JSON answers git-svn-id: svn://ttmath.org/publicrep/winix/trunk@937 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
92
core/app.cpp
92
core/app.cpp
@@ -316,7 +316,8 @@ void App::ProcessRequestThrow()
|
||||
}
|
||||
|
||||
plugin.Call(WINIX_SESSION_CHANGED);
|
||||
functions.Parse(); // parsing directories,files,functions and parameters
|
||||
functions.Parse(); // parsing directories,files,functions and parameters
|
||||
|
||||
cur.mount = system.mounts.CalcCurMount();
|
||||
|
||||
if( cur.mount->type != system.mounts.MountTypeStatic() )
|
||||
@@ -400,13 +401,51 @@ void App::SaveSessionsIfNeeded()
|
||||
|
||||
|
||||
|
||||
void App::CreateJSONAnswer()
|
||||
{
|
||||
Request & req = *cur.request;
|
||||
json_out_stream.Clear();
|
||||
|
||||
if( !req.return_info_only )
|
||||
{
|
||||
json_out_stream << L"{\n";
|
||||
|
||||
for(size_t i=1 ; i<req.out_streams.size() ; ++i)
|
||||
{
|
||||
json_out_stream << L"\"stream_" << i << L"\": \"";
|
||||
JSONescape(json_out_stream, req.out_streams[i].Str());
|
||||
json_out_stream << L"\",\n";
|
||||
}
|
||||
|
||||
json_out_stream << L"\"info\": ";
|
||||
}
|
||||
|
||||
if( req.info_serializer )
|
||||
{
|
||||
req.info_serializer->Serialize(req.info, json_out_stream, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_out_stream << L"{}";
|
||||
log << log1 << "App: Request::info_serializer not defined" << logend;
|
||||
}
|
||||
|
||||
log << log3 << "App: sending JSON answer";
|
||||
|
||||
if( !req.return_info_only )
|
||||
json_out_stream << L"}\n";
|
||||
else
|
||||
log << " (Request::info only)";
|
||||
|
||||
log << logend;
|
||||
}
|
||||
|
||||
|
||||
// !! zmienic na lepsza nazwe
|
||||
void App::MakePage()
|
||||
{
|
||||
bool sent = false;
|
||||
|
||||
|
||||
if( cur.request->page_generated || !cur.request->redirect_to.empty() || !cur.request->x_sendfile.empty() )
|
||||
return;
|
||||
|
||||
@@ -419,7 +458,7 @@ bool sent = false;
|
||||
{
|
||||
if( cur.request->function == &functions.fun_cat )
|
||||
{
|
||||
cur.request->page << cur.request->item.content;
|
||||
cur.request->out_streams[0] << cur.request->item.content; // !! CHECK ME is it ok?
|
||||
sent = true;
|
||||
}
|
||||
else
|
||||
@@ -436,12 +475,9 @@ bool sent = false;
|
||||
}
|
||||
|
||||
|
||||
if( cur.request->ajax_serializer )
|
||||
if( cur.request->return_json )
|
||||
{
|
||||
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);
|
||||
CreateJSONAnswer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,6 +512,9 @@ void App::Make()
|
||||
return;
|
||||
}
|
||||
|
||||
if( cur.request->ParamValue(L"reqtype") == L"json" )
|
||||
cur.request->return_json = true;
|
||||
|
||||
if( cur.session->ip_ban && cur.session->ip_ban->IsIPBanned() )
|
||||
{
|
||||
PT::Date date(cur.session->ip_ban->expires);
|
||||
@@ -525,11 +564,10 @@ void App::Make()
|
||||
return;
|
||||
}
|
||||
|
||||
if( !cur.request->ajax_serializer && cur.request->ParamValue(L"reqtype") == L"json")
|
||||
if( !cur.request->info_serializer )
|
||||
{
|
||||
log << log3 << "App: using generic JSON serializer" << logend;
|
||||
ajax_generic_serializer.Clear();
|
||||
cur.request->ajax_serializer = &ajax_generic_serializer;
|
||||
json_generic_serializer.Clear(); // !! IMPROVE ME add to the end of a request
|
||||
cur.request->info_serializer = &json_generic_serializer;
|
||||
}
|
||||
|
||||
plugin.Call(WINIX_CONTENT_MAKE);
|
||||
@@ -728,6 +766,7 @@ void App::CheckKonqueror()
|
||||
|
||||
|
||||
|
||||
|
||||
void App::PrepareSessionCookie()
|
||||
{
|
||||
if( !cur.session || cur.session->id==0 )
|
||||
@@ -812,7 +851,7 @@ void App::SendHeadersStatic()
|
||||
|
||||
void App::SendHeaderContentType()
|
||||
{
|
||||
if( cur.request->ajax_serializer )
|
||||
if( cur.request->return_json )
|
||||
{
|
||||
FCGX_PutS("Content-Type: application/json", fcgi_request.out);
|
||||
}
|
||||
@@ -967,7 +1006,7 @@ void App::FilterCompressSend(bool compressing, int compress_encoding, const std:
|
||||
bool raw = cur.request->is_item && cur.request->item.content_type == Item::ct_raw && cur.request->status == WINIX_ERR_OK &&
|
||||
cur.request->function && (cur.request->function == &functions.fun_cat || cur.request->function == &functions.fun_run);
|
||||
|
||||
if( config.html_filter && cur.request->use_html_filter && !raw && !cur.request->ajax_serializer )
|
||||
if( config.html_filter && cur.request->use_html_filter && !raw && !cur.request->return_json )
|
||||
{
|
||||
TemplatesFunctions::html_filter.Filter(*source, clean_html);
|
||||
AddDebugInfo(clean_html);
|
||||
@@ -992,6 +1031,9 @@ void App::FilterCompressSend(bool compressing, int compress_encoding, const std:
|
||||
compress.CompressAndPut(source_a.c_str(), source_a.length(), fcgi_request.out, compress_encoding);
|
||||
else
|
||||
FCGX_PutS(source_a.c_str(), fcgi_request.out);
|
||||
|
||||
if( cur.request->return_json )
|
||||
json_out_stream.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -1098,10 +1140,10 @@ Error status = cur.request->status;
|
||||
bool compressing;
|
||||
int compress_encoding;
|
||||
|
||||
if( cur.request->ajax_serializer )
|
||||
source = &cur.request->ajaxpage.Str();
|
||||
if( cur.request->return_json )
|
||||
source = &json_out_stream.Str();
|
||||
else
|
||||
source = &cur.request->page.Str();
|
||||
source = &cur.request->out_streams[0].Str();
|
||||
|
||||
SelectCompression(source->length(), compressing, compress_encoding);
|
||||
|
||||
@@ -1158,14 +1200,12 @@ void App::SendData(const BinaryPage & page, FCGX_Stream * out)
|
||||
|
||||
void App::SendBinaryAnswer()
|
||||
{
|
||||
BinaryPage & source = cur.request->binary_page;
|
||||
BinaryPage & compressed_page = cur.request->compressed_page;
|
||||
BinaryPage & source = cur.request->out_bin_stream;
|
||||
Header header = h_200;
|
||||
Error status = cur.request->status;
|
||||
bool compressing;
|
||||
int compress_encoding;
|
||||
|
||||
|
||||
SelectCompression(source.size(), compressing, compress_encoding);
|
||||
|
||||
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
|
||||
@@ -1182,8 +1222,10 @@ int compress_encoding;
|
||||
{
|
||||
if( compressing )
|
||||
{
|
||||
compress.Compressing(source, compressed_page, compress_encoding);
|
||||
SendData(compressed_page, fcgi_request.out);
|
||||
out_bin_stream_compressed.clear(); // !! IMPROVE ME add to the end of a request
|
||||
compress.Compressing(source, out_bin_stream_compressed, compress_encoding);
|
||||
SendData(out_bin_stream_compressed, fcgi_request.out);
|
||||
out_bin_stream_compressed.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1195,10 +1237,10 @@ int compress_encoding;
|
||||
|
||||
void App::SendAnswer()
|
||||
{
|
||||
if( cur.request->use_text_page )
|
||||
SendTextAnswer();
|
||||
else
|
||||
if( cur.request->send_bin_stream )
|
||||
SendBinaryAnswer();
|
||||
else
|
||||
SendTextAnswer();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user