You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ESI include does not process during getting 304 header #8291
When ATS receipt "304 Not Modified" header from backend, ESI does not execute and both of the esi:include and "x-esi: 1" header will be responsed to client.
P.S. http client does not send IF-NONE-MATCH header, just ATS cache revalidate
==========
The problem seem caused by content-type header checking:
if ((!checkHeaderValue(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE, "text/", 5, true)) &&
I have tried to add contype-type header in php, but it seem droped by nginx (may be ?)
Here is my lua content-type patch for ESI + 304:
================
esi_patch.lua
function do_global_read_response()
ts.debug('do_global_read_response')
local ct = ts.server_response.header['Content-Type']
local cct = ''
local cache_status = ts.http.get_cache_lookup_status()
if cache_status == TS_LUA_CACHE_LOOKUP_HIT_FRESH then
ts.debug('hit')
cct = ts.cached_response.header['Content-Type']
elseif cache_status == TS_LUA_CACHE_LOOKUP_HIT_STALE then
ts.debug('hit, stale')
cct = ts.cached_response.header['Content-Type']
else
ts.debug('not hit')
end
local code = ts.server_response.get_status()
local xesi = ts.server_response.header['X-ESI']
ts.debug('code:'..code)
ts.debug(cct)
ts.debug(xesi)
if xesi ~= nil and ct == nil and code == 304 and cct ~= nil then
ts.debug('use cct')
ts.server_response.header['Content-Type'] = cct
ts.server_response.header['X-Lua-Esi-Patch'] = 1
end
I don't think the ESI plugin currently supports the If-None-Match scenario. It can only transform a response from origin or a response from the cache. When status 304 is returned from origin, the body is empty and so there is nothing to transform.
you can instead try to remove "If-None-Match" header in the send request hook and so your origin will then not be able to send back 304 response.
um.
I applied my lua patch, it seem to get cached response from cache store and process ESI include successfully.
If the ESI plugin check the status code, and using the content-type in cached response if status code is 304.
It should make ESI in ATS work fine with 304 header.
Supporting 304 header should make ATS response faster and can help to reduce bandwidth usage.
The script looks fine. I understand your intention of making ESI plugin to support 304 status response from origin as well.
However, my question is that status 304 is normally without a response body and so why would you want an ESI processing to happen on a 304 status response from origin? Can you give me a use case?
After rereading this thread, I know I misunderstand something. Now I understand that you are trying to trigger ESI processing on the cached response while ATS is receiving the 304 response from origin.
This does look like a problem that I can provide a fix inside the plugin.
Activity
shukitchan commentedon Aug 30, 2021
I don't think the ESI plugin currently supports the If-None-Match scenario. It can only transform a response from origin or a response from the cache. When status 304 is returned from origin, the body is empty and so there is nothing to transform.
you can instead try to remove "If-None-Match" header in the send request hook and so your origin will then not be able to send back 304 response.
david187 commentedon Aug 30, 2021
um.
I applied my lua patch, it seem to get cached response from cache store and process ESI include successfully.
If the ESI plugin check the status code, and using the content-type in cached response if status code is 304.
It should make ESI in ATS work fine with 304 header.
Supporting 304 header should make ATS response faster and can help to reduce bandwidth usage.
shukitchan commentedon Aug 30, 2021
I see. So the lua script actually works for you? and it makes the plugin do a transform correctly.
Let me take a look.
david187 commentedon Aug 30, 2021
Yes, It work fine for me.
Please review for the logic is correct or not.
Thanks.
shukitchan commentedon Dec 21, 2021
The script looks fine. I understand your intention of making ESI plugin to support 304 status response from origin as well.
However, my question is that status 304 is normally without a response body and so why would you want an ESI processing to happen on a 304 status response from origin? Can you give me a use case?
shukitchan commentedon Dec 21, 2021
After rereading this thread, I know I misunderstand something. Now I understand that you are trying to trigger ESI processing on the cached response while ATS is receiving the 304 response from origin.
This does look like a problem that I can provide a fix inside the plugin.