Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare not forwarding ETag header?

I have a site (e.g. http://example.com) that uses Cloudflare. Nothing special, no weird page rules, no weird settings, free plan.

When I go to http://example.com, I get this response for the GET http://example.com request:

Cache-Control:no-cache, must-revalidate
CF-RAY:2b8d0490837f2828-SJC
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Sun, 26 Jun 2016 01:52:05 GMT
Expires:0
Pragma:no-cache
Server:cloudflare-nginx
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:Express

Notice that the response has no ETag header, even though it's enabled on my origin server.

When I go to the origin server directly, e.g. GET http://01.23.456.789/, I get this response:

Accept-Ranges:bytes
Cache-Control:no-cache, must-revalidate
Connection:keep-alive
Date:Sun, 26 Jun 2016 01:56:53 GMT
ETag:W/"4cf8-1558a5557a0"
Expires:0
Pragma:no-cache
X-Powered-By:Express

Does anyone know why Cloudflare wouldn't be forwarding the ETag header? How can I make Cloudflare forward the ETag? Cloudflare isn't caching the GET http://example.com request by default since it's an HTML page.

like image 718
Victor Zhou Avatar asked Jun 26 '16 01:06

Victor Zhou


People also ask

What is the ETag header?

The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content was not changed.

How are weak ETags different from strong ETags?

Strong ETags denote an object that is byte-for-byte identical to a cached version and allows for partial responses, such as byte-range requests. Weak ETags denote that an object is semantically equivalent.


1 Answers

I spoke with a Cloudflare Tech Support Engineer and he helped fixed my issue. For anyone in the future who might have this same problem, here's what fixed it:

I had Email Obfuscation enabled for the URL in question (that was getting its ETag header removed). According to https://support.cloudflare.com/hc/en-us/articles/218505467-Does-CloudFlare-support-ETag-headers-,

Email Obfuscation will need to be disabled, otherwise the ETag headers
will be removed from the response. Email Obfuscation modifies the code
significantly enough it cannot be considered semantically equivalent.

Disabling Email Obfuscation still didn't fix it, though. Turns out I had an app enabled that would modify the HTML, so the ETag had to be invalidated. In the end, setting a Page Rule with Disable Security, Disable Apps, Disable Performance for that URL did the trick.

like image 70
Victor Zhou Avatar answered Sep 17 '22 19:09

Victor Zhou