I'd like to use etag caching directly in my application / verify the eTag in my Application. How is it possible to route the "If-None-Match" header to the backends? It seems that Varnish is cutting out this header by default.
Asked
Active
Viewed 1,021 times
2 Answers
1
You can rewrite it to a different header that varnish doesn't know about, and then read that header in your backend instead.
At the top of vcl_recv, try:
set req.http.X-If-None-Match-Previously = req.http.If-None-Match;
and then read the X-If-None-Match-Previously header in your application.
I'm not sure how that's going to interact with your caching but that will pass the header data through if Varnish is stripping it from its backend requests.

Pax
- 335
- 2
- 8
-
Are you sure that it should work? I'm sending the headers but the app does not receive anything. even set req.http.X-If-None-Match-Previously = "test"; does not work. – Tobias Jul 28 '12 at 08:05
-
Any ideas? Seems not to be possible to add various headers? – Tobias Jul 31 '12 at 13:21
-
Definitely possible. Is there something between varnish and your app that might be stripping them? – Pax Aug 01 '12 at 01:28
-
Okay, may fault: set req.http.X-If-None-Match-Previously = "foo" works now. But it seems that req.http.If-None-Match was stripped before by Varnish :-( Any Ideas on this? Inline C? – Tobias Aug 01 '12 at 13:56
-
Stupid me, see the real solution below. – Tobias Aug 01 '12 at 15:53
-
This yields a compile error with Varnish 6: `Cannot be set in method 'vcl_backend_response' Running VCC-compiler failed, exited with 2` – maxschlepzig May 12 '19 at 11:46
0
Okay, solved it: Varnish does not remove the If-None-Match header. It was just my web app delivered from cache while requests were still coming in. Chrome served the old version of the page. COUGH. COUGH. COUGH.

Tobias
- 161
- 1
- 6
-
1This answer (https://stackoverflow.com/a/21194946/271351), and my experience, seem to contradict this statement. – cjbarth Jan 04 '19 at 19:10