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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ private:
|
||||
std::wstring http_header_name;
|
||||
std::wstring http_header_value;
|
||||
std::string http_header_8bit;
|
||||
std::wstring empty_response;
|
||||
|
||||
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
|
||||
morm::JSONConnector json_connector;
|
||||
@@ -206,6 +207,7 @@ private:
|
||||
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
|
||||
void LogAccess();
|
||||
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
||||
const std::wstring * CreateFrameAnswer();
|
||||
void CreateJSONAnswer();
|
||||
|
||||
void ReadRequest();
|
||||
|
||||
Reference in New Issue
Block a user