Skip to content

ESI include does not process during getting 304 header #8291

Description

@david187

version: ats 9.1.0

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

return 0
end

=======
esi_etag.php

Hello, $etag = '"'.md5($output).'"';

$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
$_SERVER['HTTP_IF_NONE_MATCH'] :
false ;

if($if_none_match == $etag ){
header("HTTP/1.1 304 Not Modified");
exit;
}

header('cache-control: public, max-age=10');
header('etag: '.$etag);

echo $output;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions