added basic support for htmx (ajax)

- if there is HX-Request header present we sent only a part of the whole html
- we return only specific stream defined by [out ...] ezc statement
- the name of the stream is passed in the 'frame' parameter
  (if not present then 'content' is assumed)
- added ezc function: winix_is_htmx_request
This commit is contained in:
2021-05-27 19:36:04 +02:00
parent 1292a56d1b
commit ba331dea4a
8 changed files with 257 additions and 7 deletions

View File

@@ -724,6 +724,25 @@ void App::SaveSessionsIfNeeded()
const std::wstring * App::CreateFrameAnswer()
{
Request & req = *cur.request;
auto i = req.out_streams.streams_map.begin();
const std::wstring * frame = cur.request->ParamValuep(L"frame");
for( ; i != req.out_streams.streams_map.end() ; ++i)
{
if( (frame && i->first == *frame) || (!frame && i->first == L"content") )
{
return &i->second->Str();
break;
}
}
return nullptr;
}
void App::CreateJSONAnswer()
{
Request & req = *cur.request;
@@ -1764,11 +1783,12 @@ return header;
void App::SendTextAnswer()
{
const std::wstring * source;
const std::wstring * source = nullptr;
bool compressing = false;
int compress_encoding = 0;
size_t output_size = 0;
Header header = GetHTTPStatusCode();
if( CanSendContent() )
@@ -1781,6 +1801,17 @@ size_t output_size = 0;
source = &json_out_stream.Str(); // json_out_stream was prepared by CreateJSONAnswer()
}
else
if( cur.request->headers_in.has_key(L"HX-Request") || cur.request->headers_in.has_key(L"hx_request") ) // fastcgi will change the header to hx_request
{
source = CreateFrameAnswer();
if( !source )
{
empty_response.clear();
source = &empty_response;
}
}
else
{
source = &cur.request->out_main_stream.Str();
}