- json_generic_serializer was not set when there was a redirect

- if there is a redirect and the json return answer is requested
  then we send 'redirect_to' field in 'info' space




git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1169 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2019-02-19 10:36:20 +00:00
parent 4f8db81c85
commit 8895f0dcac
4 changed files with 49 additions and 30 deletions

View File

@@ -810,12 +810,6 @@ void App::Make()
return;
}
if( !cur.request->info_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);
MakePage();
}
@@ -1486,7 +1480,7 @@ void App::PrepareHeaders(bool compressing, int compress_encoding, Header header,
if( cur.request->send_as_attachment )
AddHeader(L"Content-Disposition", L"attachment");
if( !cur.request->redirect_to.empty() )
if( !cur.request->redirect_to.empty() && !cur.request->return_json )
{
PrepareHeadersRedirect();
}
@@ -1510,6 +1504,23 @@ void App::PrepareHeaders(bool compressing, int compress_encoding, Header header,
}
void App::PrepareStandardJSONFields()
{
PT::Space & info = cur.request->info;
if( !info.GetFirstValue(L"status") )
{
info.Add(L"status", cur.request->status);
}
if( !cur.request->redirect_to.empty() && !info.GetFirstValue(L"redirect_to") )
{
info.Add(L"redirect_to", cur.request->redirect_to);
}
}
void App::FilterContent()
{
@@ -1618,9 +1629,23 @@ void App::SelectCompression(size_t source_len, bool & compression_allowed, int &
bool App::CanSendContent()
{
if( !cur.request->redirect_to.empty() || !cur.request->x_sendfile.empty() )
// if there is a redirect or a file to send then we do not send a content
if( !cur.request->x_sendfile.empty() )
{
// if there is a file to send then we do not send a content
return false;
}
if( cur.request->return_json )
{
// if there is a redirect flag then it will be put to info struct
return true;
}
if( !cur.request->redirect_to.empty() )
{
// if there is a redirect and no json is requred then we do not send the content
return false;
}
/*
we don't have to check the HEAD method
@@ -1785,6 +1810,15 @@ int compress_encoding;
void App::SendAnswer()
{
if( !cur.request->info_serializer )
{
json_generic_serializer.Clear(); // !! IMPROVE ME add to the end of a request
cur.request->info_serializer = &json_generic_serializer;
}
if( cur.request->return_json )
PrepareStandardJSONFields();
if( cur.request->send_bin_stream )
SendBinaryAnswer();
else