- 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:
Tomasz Sowa 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

View File

@ -250,6 +250,7 @@ private:
void PrepareHeadersCompression(int compress_encoding);
void PrepareHeadersNormal(Header header, size_t output_size);
void PrepareHeaders(bool compressing, int compress_encoding, Header header, size_t output_size);
void PrepareStandardJSONFields();
int SelectDeflateVersion();
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
bool CanSendContent();

View File

@ -106,19 +106,6 @@ return true;
*/
// !! zmienic nazwy
// albo w ogole te metody nie sa potrzebne teraz (byly zmiany)
void Emacs::DoRedirectIfNeeded(bool adding)
{
if( cur->request->ParamValue(L"reqtype") != L"json" )
{
system->RedirectTo(cur->request->item);
}
}
int Emacs::NotifyCodeEdit()
{
// !! nie potrzebne
@ -172,19 +159,17 @@ void Emacs::MakePost()
if( cur->request->status == WINIX_ERR_OK )
{
DoRedirectIfNeeded(adding);
if( adding )
{
system->RedirectToLastFunction(nullptr, false);
}
functions->CheckSpecialFile(cur->request->item);
}
else
{
log << log1 << "Emacs: error: " << cur->request->status << logend;
}
if( cur->request->ParamValue(L"reqtype") == L"json" )
{
cur->request->info.Add(L"status", cur->request->status);
}
}

View File

@ -56,7 +56,6 @@ public:
private:
bool HasAccess(const Item & item); // !! takie funkcje to nie powinny byc skladowe modelu?
void DoRedirectIfNeeded(bool adding);
int NotifyCodeEdit();
int NotifyCodeAdd();