From 8895f0dcac38042aab66fb537275c31448ee6069 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 19 Feb 2019 10:36:20 +0000 Subject: [PATCH] - 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 --- winixd/core/app.cpp | 52 +++++++++++++++++++++++++++++++------- winixd/core/app.h | 1 + winixd/functions/emacs.cpp | 25 ++++-------------- winixd/functions/emacs.h | 1 - 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 67c365c..bb5f30f 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -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 diff --git a/winixd/core/app.h b/winixd/core/app.h index 1374d98..f2348d8 100644 --- a/winixd/core/app.h +++ b/winixd/core/app.h @@ -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(); diff --git a/winixd/functions/emacs.cpp b/winixd/functions/emacs.cpp index a8fd6ca..bf12cb5 100644 --- a/winixd/functions/emacs.cpp +++ b/winixd/functions/emacs.cpp @@ -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); - } } diff --git a/winixd/functions/emacs.h b/winixd/functions/emacs.h index 09f7f38..60f990a 100644 --- a/winixd/functions/emacs.h +++ b/winixd/functions/emacs.h @@ -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();