Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: a little more flexibility on NotFound #10707

Closed
tucnak opened this issue May 5, 2015 · 1 comment
Closed

net/http: a little more flexibility on NotFound #10707

tucnak opened this issue May 5, 2015 · 1 comment

Comments

@tucnak
Copy link

tucnak commented May 5, 2015

This issue implies Go v1.4.2 on darwin/amd64 architecture.

Currently, http.NotFoundHandler, that replies to all 404 requests has the following implementation:

// NotFound replies to the request with an HTTP 404 not found error.
func NotFound(w ResponseWriter, r *Request) { Error(w, "404 page not found", StatusNotFound) }

// NotFoundHandler returns a simple request handler
// that replies to each request with a ``404 page not found'' reply.
func NotFoundHandler() Handler { return HandlerFunc(NotFound) }
//   ^^^^^^^^^^^^^^^

This works pretty great for a helloworld application, but in the wild you would need to override default 404 page with a custom one. In the meantime, implementing your own 404 handler is not an issue at all, unless it's being called by FileServer() or ServeFile, which people are using to serve some static.

In my opinion, http.NotFoundHandler is not flexible enough and we must have a way to override it with custom 404 error handler.

@bradfitz
Copy link
Contributor

bradfitz commented May 5, 2015

This has come up a number of times before on the issue tracker and mailing lists. You can implement your own ResponseWriter which writes a custom message after WriteHeader.

The net/http package will not be growing a pluggable template system.

@bradfitz bradfitz closed this as completed May 5, 2015
@mikioh mikioh changed the title http: a little more flexibility on NotFound net/http: a little more flexibility on NotFound May 6, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants