{"action":"created","issue":{"url":"https://api.github.com/repos/rtomayko/rack-cache/issues/111","labels_url":"https://api.github.com/repos/rtomayko/rack-cache/issues/111/labels{/name}","comments_url":"https://api.github.com/repos/rtomayko/rack-cache/issues/111/comments","events_url":"https://api.github.com/repos/rtomayko/rack-cache/issues/111/events","html_url":"https://github.com/rtomayko/rack-cache/issues/111","id":67848119,"number":111,"title":"Cache hit gives 200 instead of 304 when behind Nginx","user":{"login":"jackdesert","id":791315,"avatar_url":"https://avatars.githubusercontent.com/u/791315?v=3","gravatar_id":"","url":"https://api.github.com/users/jackdesert","html_url":"https://github.com/jackdesert","followers_url":"https://api.github.com/users/jackdesert/followers","following_url":"https://api.github.com/users/jackdesert/following{/other_user}","gists_url":"https://api.github.com/users/jackdesert/gists{/gist_id}","starred_url":"https://api.github.com/users/jackdesert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackdesert/subscriptions","organizations_url":"https://api.github.com/users/jackdesert/orgs","repos_url":"https://api.github.com/users/jackdesert/repos","events_url":"https://api.github.com/users/jackdesert/events{/privacy}","received_events_url":"https://api.github.com/users/jackdesert/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-12T00:02:26Z","updated_at":"2015-04-14T05:41:47Z","closed_at":"2015-04-14T05:41:47Z","body":"How do I get rack-cache to return a 304 when behind nginx?\r\n\r\nHere is a sinatra example with etag that works functionally, but when used behind nginx it returns a status code of 200 when I expected a 304. When accessed directly (without nginx) it returns a 304 most of the time, as expected.\r\n\r\n    get '/' do\r\n      cache_control :public\r\n      the_etag = \"#{Message.last.try(:id)}\"\r\n      etag the_etag\r\n      \"cache: #{Time.now}, etag: #{the_etag}\"\r\n    end\r\n\r\nHere is the Sinatra log:\r\n\r\n    cache: [GET /] stale, valid, store\r\n    127.0.0.1 - - [12/Apr/2015:03:52:55 -0400] \"GET / HTTP/1.0\" 200 91093 0.0039\r\n\r\nBy halting at a breakpoint during the request both with_nginx and without_nxinx, those parts of env that show up with ALL_CAPS keys were captured. Showing only the diff:\r\n\r\n    $ diff with_nginx without_nginx\r\n    3c3\r\n    < \"rack.input\"=>#<StringIO:0x007f5ae98891b8>,\r\n    ---\r\n    > \"rack.input\"=>#<StringIO:0x007f5aeb287ec0>,\r\n    12,16c12,15\r\n    < \"HTTP_VERSION\"=>\"HTTP/1.0\",\r\n    < \"HTTP_HOST\"=>\"example.com\",\r\n    < \"HTTP_CONNECTION\"=>\"close\",\r\n    ---\r\n    > \"HTTP_VERSION\"=>\"HTTP/1.1\",\r\n    > \"HTTP_HOST\"=>\"example.com:8852\",\r\n    22c21\r\n    ---\r\n    > \"HTTP_CONNECTION\"=>\"keep-alive\",\r\n    24c23\r\n    < \"SERVER_PORT\"=>\"80\",\r\n    ---\r\n    > \"SERVER_PORT\"=>\"8852\",\r\n    28c27\r\n    < \"REMOTE_ADDR\"=>\"127.0.0.1\",\r\n    ---\r\n    > \"REMOTE_ADDR\"=>\"74.59.192.69\",\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rtomayko/rack-cache/issues/comments/92614509","html_url":"https://github.com/rtomayko/rack-cache/issues/111#issuecomment-92614509","issue_url":"https://api.github.com/repos/rtomayko/rack-cache/issues/111","id":92614509,"user":{"login":"jackdesert","id":791315,"avatar_url":"https://avatars.githubusercontent.com/u/791315?v=3","gravatar_id":"","url":"https://api.github.com/users/jackdesert","html_url":"https://github.com/jackdesert","followers_url":"https://api.github.com/users/jackdesert/followers","following_url":"https://api.github.com/users/jackdesert/following{/other_user}","gists_url":"https://api.github.com/users/jackdesert/gists{/gist_id}","starred_url":"https://api.github.com/users/jackdesert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackdesert/subscriptions","organizations_url":"https://api.github.com/users/jackdesert/orgs","repos_url":"https://api.github.com/users/jackdesert/repos","events_url":"https://api.github.com/users/jackdesert/events{/privacy}","received_events_url":"https://api.github.com/users/jackdesert/received_events","type":"User","site_admin":false},"created_at":"2015-04-14T05:41:47Z","updated_at":"2015-04-14T05:41:47Z","body":"Found the answer here: http://forum.nginx.org/read.php?2,242807,242809#msg-242809\r\nThe etag was being stripped by nginx because gzip compression was enabled. \r\nHad to disable gzip compression in nginx to get it to work."}}