summary refs log tree commit diff
path: root/pkgs/servers/http
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-12-30 14:06:00 +0100
committeraszlig <aszlig@nix.build>2019-12-30 14:30:36 +0100
commitccf55bead1f3bc2a6419a9fdcec55933ffe046de (patch)
treeb31f9e07b8f8fc7839385ee17f650da646e50944 /pkgs/servers/http
parent646c641358de1c0856bfe46e369c45fd5a8fd617 (diff)
downloadnixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar.gz
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar.bz2
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar.lz
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar.xz
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.tar.zst
nixpkgs-ccf55bead1f3bc2a6419a9fdcec55933ffe046de.zip
nginx: Clear Last-Modified if ETag is from store
This is what I've suspected a while ago[1]:

> Heads-up everyone: After testing this in a few production instances,
> it seems that some browsers still get cache hits for new store paths
> (and changed contents) for some reason. I highly suspect that it might
> be due to the last-modified header (as mentioned in [2]).
>
> Going to test this with last-modified disabled for a little while and
> if this is the case I think we should improve that patch by disabling
> last-modified if serving from a store path.

Much earlier[2] when I reviewed the patch, I wrote this:

> Other than that, it looks good to me.
>
> However, I'm not sure what we should do with Last-Modified header.
> From RFC 2616, section 13.3.4:
>
> - If both an entity tag and a Last-Modified value have been
>   provided by the origin server, SHOULD use both validators in
>   cache-conditional requests. This allows both HTTP/1.0 and
>   HTTP/1.1 caches to respond appropriately.
>
> I'm a bit nervous about the SHOULD here, as user agents in the wild
> could possibly just use Last-Modified and use the cached content
> instead.

Unfortunately, I didn't pursue this any further back then because
@pbogdan noted[3] the following:

> Hmm, could they (assuming they are conforming):
>
>  * If an entity tag has been provided by the origin server, MUST
>    use that entity tag in any cache-conditional request (using If-
>    Match or If-None-Match).

Since running with this patch in some deployments, I found that both
Firefox and Chrome/Chromium do NOT re-validate against the ETag if the
Last-Modified header is still the same.

So I wrote a small NixOS VM test with Geckodriver to have a test case
which is closer to the real world and I indeed was able to reproduce
this.

Whether this is actually a bug in Chrome or Firefox is an entirely
different issue and even IF it is the fault of the browsers and it is
fixed at some point, we'd still need to handle this for older browser
versions.

Apart from clearing the header, I also recreated the patch by using a
plain "git diff" with a small description on top. This should make it
easier for future authors to work on that patch.

[1]: https://github.com/NixOS/nixpkgs/pull/48337#issuecomment-495072764
[2]: https://github.com/NixOS/nixpkgs/pull/48337#issuecomment-451644084
[3]: https://github.com/NixOS/nixpkgs/pull/48337#issuecomment-451646135

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/servers/http')
-rw-r--r--pkgs/servers/http/nginx/nix-etag-1.15.4.patch18
1 files changed, 5 insertions, 13 deletions
diff --git a/pkgs/servers/http/nginx/nix-etag-1.15.4.patch b/pkgs/servers/http/nginx/nix-etag-1.15.4.patch
index 9dec715bf6c..c1473ccdb1b 100644
--- a/pkgs/servers/http/nginx/nix-etag-1.15.4.patch
+++ b/pkgs/servers/http/nginx/nix-etag-1.15.4.patch
@@ -1,14 +1,8 @@
-From f6a978f024d01202f954483423af1b2d5d5159a6 Mon Sep 17 00:00:00 2001
-From: Yegor Timoshenko <yegortimoshenko@riseup.net>
-Date: Fri, 28 Sep 2018 03:27:04 +0000
-Subject: [PATCH] If root is in Nix store, set ETag to its path hash
-
----
- src/http/ngx_http_core_module.c | 56 +++++++++++++++++++++++++++++----
- 1 file changed, 50 insertions(+), 6 deletions(-)
+This patch makes it possible to serve static content from Nix store paths, by
+using the hash of the store path for the ETag header.
 
 diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
-index c57ec00c..b7992de2 100644
+index cb49ef74..f88dc77c 100644
 --- a/src/http/ngx_http_core_module.c
 +++ b/src/http/ngx_http_core_module.c
 @@ -1583,6 +1583,7 @@ ngx_http_set_etag(ngx_http_request_t *r)
@@ -19,7 +13,7 @@ index c57ec00c..b7992de2 100644
  
      clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  
-@@ -1598,16 +1599,61 @@ ngx_http_set_etag(ngx_http_request_t *r)
+@@ -1598,16 +1599,62 @@ ngx_http_set_etag(ngx_http_request_t *r)
      etag->hash = 1;
      ngx_str_set(&etag->key, "ETag");
  
@@ -68,6 +62,7 @@ index c57ec00c..b7992de2 100644
 +        }
 +
 +        ngx_memcpy(etag->value.data, ptr1, etag->value.len);
++        ngx_http_clear_last_modified(r);
 +    } else {
 +        etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
 +
@@ -87,6 +82,3 @@ index c57ec00c..b7992de2 100644
  
      r->headers_out.etag = etag;
  
--- 
-2.19.0
-