Skip to content

Commit

Permalink
Merge pull request #21 from fasterize/etag_validation
Browse files Browse the repository at this point in the history
Replace Etag by ETag
  • Loading branch information
bpaquet committed May 30, 2018
2 parents 9e774a1 + a87b7fb commit b58a450
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.markdown
Expand Up @@ -15,6 +15,7 @@ This module is based on the standard [Nginx Memcached module](http://wiki.nginx.
* Get memcached'stats, via HTTP request to nginx
* Manage key namespaces, for partial memcached flush
* Reply `304 Not Modified` for request with `If-Modified-Since` headers and content with `Last-Modified` in cache
* Reply `304 Not Modified` for request with `If-None-Match` headers and content with `ETag` in cache
* Set custom HTTP code to send redirect

You can find some explanations qbout why this module has been created in this [blog post](http://blog.octo.com/en/http-caching-with-nginx-and-memcached/).
Expand Down Expand Up @@ -225,7 +226,9 @@ You can flush a namespace (in reality, it only increment the key prefix) with a
304 Not Modified
===

For request with HTTP Header `If-Modified-Since`, and associated resource in memcached with HTTP Headers `Last-Modified`, the module will send a 304 Not Modified if resource has not been modified, and if Nginx [configuration](http://wiki.nginx.org/HttpCoreModule#if_modified_since) allows this behaviour.
For request with HTTP Header `If-Modified-Since`, and associated resource in memcached with HTTP Header `Last-Modified`, the module will send a 304 Not Modified if resource has not been modified, and if Nginx [configuration](http://wiki.nginx.org/HttpCoreModule#if_modified_since) allows this behaviour.

For request with HTTP Header `If-None-Match`, and associated resource in memcached with HTTP Header `ETag`, the module will send a 304 Not Modified if resource has not been modified.

License
===
Expand Down
2 changes: 1 addition & 1 deletion ngx_http_enhanced_memcached_module.c
Expand Up @@ -1240,7 +1240,7 @@ ngx_http_enhanced_memcached_process_request_get(ngx_http_request_t *r)
return NGX_ERROR;
}

if (h->key.len == sizeof("Etag") - 1 && ngx_strncmp(h->key.data, "Etag", h->key.len) == 0) {
if (h->key.len == sizeof("ETag") - 1 && ngx_strncmp(h->key.data, "ETag", h->key.len) == 0) {
etag = h;
}

Expand Down
16 changes: 8 additions & 8 deletions tests/ns_test.rb
Expand Up @@ -487,19 +487,19 @@ def test_last_modified_png
end

def test_if_none_match
put '/toto', "EXTRACT_HEADERS\r\nMyHeader: tata\r\nEtag: foo\r\n\r\nthis content", @put_domain
put '/toto', "EXTRACT_HEADERS\r\nMyHeader: tata\r\nETag: foo\r\n\r\nthis content", @put_domain
assert_stored
get '/toto', @std_domain
assert_last_response "200", "application/octet-stream", 'this content'
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
get '/toto', @std_domain, {"If-None-Match" => "bar"}
assert_last_response "200", "application/octet-stream", 'this content'
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
get '/toto', @std_domain, {"If-None-Match" => "foo"}
assert_last_response_code "304"
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
assert_nil @resp["Content-Type"]
assert_nil @resp["Content-Length"]
Expand All @@ -508,19 +508,19 @@ def test_if_none_match

def test_if_none_match_png
png = load_bin_file('show_48.png')
put '/png', "EXTRACT_HEADERS\r\nMyHeader: tata\r\nEtag: foo\r\nContent-Type: image/png\r\n\r\n" + png, @put_domain
put '/png', "EXTRACT_HEADERS\r\nMyHeader: tata\r\nETag: foo\r\nContent-Type: image/png\r\n\r\n" + png, @put_domain
assert_stored
get '/png', @std_domain
assert_last_response "200", "image/png", png
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
get '/png', @std_domain, {"If-None-Match" => "bar"}
assert_last_response "200", "image/png", png
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
get '/png', @std_domain, {"If-None-Match" => "foo"}
assert_last_response_code "304"
assert_equal "foo", @resp['Etag']
assert_equal "foo", @resp['ETag']
assert_equal "tata", @resp["MyHeader"]
assert_nil @resp["Content-Type"]
assert_nil @resp["Content-Length"]
Expand Down

0 comments on commit b58a450

Please sign in to comment.