Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: custom error handlers for http.FileServer #27139
Noticed that in Go 1.11 a error handler field was added to httputil's ReverseProxy to allow sending allow writing a custom error.
I think the same should be done for http.FileServer, http.ServeFile and http.ServeContent.
I don't see an easy way to do this without breaking the API or adding more API so maybe this is better for Go 2.
You can do it today outside of the stdlib by wrapping the http.ResponseWriter with your own writer and intercepting the call to WriteHeader, and then, using the status code from there to decide whether you want to serve an error.
It is a little slow, involved and quirky though.