do not send content when there is a htmx redirect
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021-2023, Tomasz Sowa
|
||||
* Copyright (c) 2021-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -63,6 +63,18 @@ public:
|
||||
static constexpr const wchar_t * access_control_expose_headers = L"Access-Control-Expose-Headers";
|
||||
static constexpr const wchar_t * access_control_max_age = L"Access-Control-Max-Age";
|
||||
|
||||
static constexpr const wchar_t * hx_location = L"HX-Location";
|
||||
static constexpr const wchar_t * hx_push_url = L"HX-Push-Url";
|
||||
static constexpr const wchar_t * hx_redirect = L"HX-Redirect";
|
||||
static constexpr const wchar_t * hx_refresh = L"HX-Refresh";
|
||||
static constexpr const wchar_t * hx_replace_url = L"HX-Replace-Url";
|
||||
static constexpr const wchar_t * hx_reswap = L"HX-Reswap";
|
||||
static constexpr const wchar_t * hx_retarget = L"HX-Retarget";
|
||||
static constexpr const wchar_t * hx_reselect = L"HX-Reselect";
|
||||
static constexpr const wchar_t * hx_trigger = L"HX-Trigger";
|
||||
static constexpr const wchar_t * hx_trigger_after_settle = L"HX-Trigger-After-Settle";
|
||||
static constexpr const wchar_t * hx_trigger_after_swap = L"HX-Trigger-After-Swap";
|
||||
|
||||
/*
|
||||
* headers' names lower case
|
||||
*/
|
||||
|
||||
@@ -854,9 +854,6 @@ void Request::ModifyStatusForRedirect()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// may rename to something like PrepareAndSendAnswer()?
|
||||
void Request::PrepareAndSendAnswer()
|
||||
{
|
||||
@@ -874,7 +871,7 @@ void Request::PrepareAndSendAnswer()
|
||||
}
|
||||
}
|
||||
|
||||
if( !redirect_to.empty() || !x_sendfile.empty() || method == Request::options )
|
||||
if( method == Request::options || !redirect_to.empty() || !x_sendfile.empty() || has_htmx_redirect() )
|
||||
{
|
||||
Send8bitOutput(output_8bit); // send empty content
|
||||
return;
|
||||
@@ -2259,6 +2256,21 @@ void Request::PutMethodName(pt::Stream & stream)
|
||||
}
|
||||
|
||||
|
||||
bool Request::has_htmx_redirect()
|
||||
{
|
||||
if( out_headers.has_key(Header::hx_redirect) ||
|
||||
out_headers.has_key(Header::hx_location) ||
|
||||
out_headers.has_key(Header::hx_refresh) )
|
||||
return true;
|
||||
|
||||
pt::Space * trigger = out_headers.get_space(Header::hx_trigger);
|
||||
|
||||
if( trigger && trigger->has_key(L"winix:redirect") )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Request::AddCookie(
|
||||
const std::wstring & name,
|
||||
|
||||
@@ -542,6 +542,8 @@ public:
|
||||
static void PutMethodName(Request::Method method, pt::Stream & stream);
|
||||
void PutMethodName(pt::Stream & stream);
|
||||
|
||||
bool has_htmx_redirect();
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
|
||||
Reference in New Issue
Block a user