{"action":"created","issue":{"url":"https://api.github.com/repos/julienschmidt/httprouter/issues/40","labels_url":"https://api.github.com/repos/julienschmidt/httprouter/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/julienschmidt/httprouter/issues/40/comments","events_url":"https://api.github.com/repos/julienschmidt/httprouter/issues/40/events","html_url":"https://github.com/julienschmidt/httprouter/issues/40","id":46119413,"number":40,"title":"Cache-Control headers for static files using ServeFiles","user":{"login":"einthusan","id":1294473,"avatar_url":"https://avatars.githubusercontent.com/u/1294473?v=3","gravatar_id":"","url":"https://api.github.com/users/einthusan","html_url":"https://github.com/einthusan","followers_url":"https://api.github.com/users/einthusan/followers","following_url":"https://api.github.com/users/einthusan/following{/other_user}","gists_url":"https://api.github.com/users/einthusan/gists{/gist_id}","starred_url":"https://api.github.com/users/einthusan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/einthusan/subscriptions","organizations_url":"https://api.github.com/users/einthusan/orgs","repos_url":"https://api.github.com/users/einthusan/repos","events_url":"https://api.github.com/users/einthusan/events{/privacy}","received_events_url":"https://api.github.com/users/einthusan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/julienschmidt/httprouter/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-10-17T16:42:38Z","updated_at":"2015-01-22T13:22:06Z","closed_at":null,"body":"I am not sure how to do this... is there support for this? It seems the API does not allow for such thing."},"comment":{"url":"https://api.github.com/repos/julienschmidt/httprouter/issues/comments/71019015","html_url":"https://github.com/julienschmidt/httprouter/issues/40#issuecomment-71019015","issue_url":"https://api.github.com/repos/julienschmidt/httprouter/issues/40","id":71019015,"user":{"login":"whit3","id":3913683,"avatar_url":"https://avatars.githubusercontent.com/u/3913683?v=3","gravatar_id":"","url":"https://api.github.com/users/whit3","html_url":"https://github.com/whit3","followers_url":"https://api.github.com/users/whit3/followers","following_url":"https://api.github.com/users/whit3/following{/other_user}","gists_url":"https://api.github.com/users/whit3/gists{/gist_id}","starred_url":"https://api.github.com/users/whit3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whit3/subscriptions","organizations_url":"https://api.github.com/users/whit3/orgs","repos_url":"https://api.github.com/users/whit3/repos","events_url":"https://api.github.com/users/whit3/events{/privacy}","received_events_url":"https://api.github.com/users/whit3/received_events","type":"User","site_admin":false},"created_at":"2015-01-22T13:22:06Z","updated_at":"2015-01-22T13:22:06Z","body":"A `ServeFiles`-like function is only used for serving files directly from the provided `http.Dir` so:\r\n\r\n* This function already writes in the `http.ResponseWriter`'s body : a whole access to it can be misleading and error-prone.\r\nI would just provide the `http.Header` (given by the `w.Header()`) instead of the whole `http.ResponseWriter`.\r\n\r\n* I don't see why the `*http.Request` could be useful:\r\n  * The request body doesn't have an impact over the served file.\r\n  * The request headers can't contain interesting key/values for the response.  \r\nA `r.Header.Get(\"Accept-Encoding\")` could be interesting if the body was writable, but it's not the case.\r\n\r\n* I don't see why the whole `httprouter.Params` could be useful: only the `filepath` parameter could be used for logging or something like that.\r\n\r\nHere is my proposition:\r\n\r\n```go\r\nfunc fileCacheSetter(h http.Header, fp string) {\r\n\tlog.Printf(\"Requested file path: %s\\n\", fp)\r\n\tw.Header().Set(\"Vary\", \"Accept-Encoding\")\r\n\tw.Header().Set(\"Cache-Control\", \"public, max-age=7776000\")\r\n}\r\n\r\nrouter.ServeHeadedFiles(\"/src/*filepath\", http.Dir(\"/var/www\"), fileCacheSetter)\r\n```\r\n\r\nOr, even better (for me), you could just provide a \"one-line magic\" function with a built-in gzipping and cache headers setting for a given `max-age`:\r\n\r\n```go\r\nrouter.ServeStaticFiles(\"/src/*filepath\", http.Dir(\"/var/www\"), 7776000)\r\n```"}}