From c4b55659951d8708ec96838d53962c0450289aff Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 8 Oct 2021 03:08:11 +0200 Subject: [PATCH] don't check for request->is_htmx_request for sending frames, check only "frame" url paremeter added config parameter: request_frame_parameter, default: "frame" --- winixd/core/app.cpp | 24 +++++++++++++++++++----- winixd/core/app.h | 1 + winixd/core/config.cpp | 1 + winixd/core/config.h | 4 ++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 68444f0..5e1ee3f 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -780,13 +780,16 @@ pt::WTextStream * App::CreateFrameAnswer() { Request & req = *cur.request; auto i = req.out_streams.streams_map.begin(); - const std::wstring * frame = cur.request->ParamValuep(L"frame"); + const std::wstring * frame = cur.request->ParamValuep(config.request_frame_parameter); - for( ; i != req.out_streams.streams_map.end() ; ++i) + if( frame ) { - if( (frame && i->first == *frame) || (!frame && i->first == L"content") ) + for( ; i != req.out_streams.streams_map.end() ; ++i) { - return &i->second->get_buffer(); + if( i->first == *frame ) + { + return &i->second->get_buffer(); + } } } @@ -1904,6 +1907,16 @@ return header; } +bool App::IsRequestedFrame() +{ + if( !config.request_frame_parameter.empty() ) + { + return cur.request->ParamValuep(config.request_frame_parameter); + } + + return false; +} + void App::SendTextAnswer() { @@ -1923,12 +1936,13 @@ size_t output_size = 0; */ FilterContent(); + // cur.request->return_json is depracated, we will create json from models/space registered through request->models object if( cur.request->return_json ) { source = CreateJSONAnswer(); } else - if( cur.request->is_htmx_request ) + if( IsRequestedFrame() ) { source = CreateFrameAnswer(); diff --git a/winixd/core/app.h b/winixd/core/app.h index 5a23e03..ae90f17 100644 --- a/winixd/core/app.h +++ b/winixd/core/app.h @@ -226,6 +226,7 @@ private: void CheckHtmx(); void SetSubdomain(); + bool IsRequestedFrame(); Header GetHTTPStatusCode(); void PrepareSessionCookie(); diff --git a/winixd/core/config.cpp b/winixd/core/config.cpp index 510d920..d85f5d9 100644 --- a/winixd/core/config.cpp +++ b/winixd/core/config.cpp @@ -284,6 +284,7 @@ void Config::AssignValues(bool stdout_is_closed) ezc_max_elements = Size(L"ezc_max_elements", 50000); ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000); ezc_out_streams_size = Size(L"ezc_out_streams_size", 128); + request_frame_parameter = Text(L"request_frame_parameter", L"frame"); account_need_email_verification = Bool(L"account_need_email_verification", true); reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400); diff --git a/winixd/core/config.h b/winixd/core/config.h index 7efd517..3fcf0c8 100644 --- a/winixd/core/config.h +++ b/winixd/core/config.h @@ -672,6 +672,10 @@ public: // default: 128 size_t ezc_out_streams_size; + // the name of the url parameter for returning a frame, e.g. https://domain.tld/mydir/myfunction/frame:foo + // default: frame + std::wstring request_frame_parameter; + // when true then when a user want to create a new account // he has to provide his email and a message will be sent back to him // with a link to activate the account