david187 opened a new issue #8291:
URL: https://github.com/apache/trafficserver/issues/8291


   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:
   
   
https://github.com/apache/trafficserver/blob/e44ca802404ed99899d43163fc65e1811ba791af/plugins/esi/esi.cc#L1308
   
   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
   
   <?php
   header('X-Esi: 1');
   $output = ob_get_contents();
   
   ob_end_clean();
   ?>
   <html>
   <body>
   Hello, <esi:include src="/esi/date.php"/>
   </body>
   </html>
   <?php
   
   $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;


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to