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/httputil: add a custom-error-page ResponseWriter wrapper type #15034

Closed
bep opened this issue Mar 31, 2016 · 6 comments
Closed

net/http/httputil: add a custom-error-page ResponseWriter wrapper type #15034

bep opened this issue Mar 31, 2016 · 6 comments
Labels
FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bep
Copy link
Contributor

bep commented Mar 31, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

Not relevant.

  1. What operating system and processor architecture are you using (go env)?

Not relevant.

  1. What did you do?

Try to present a nice 404.html to the end user on Page Not Found when using the Go builtin file server.

  1. What did you expect to see?

This should be a common enough use case that I shouldn't have to drag big external libraries in to solve this.

  1. What did you see instead?

That I had to drag in big external libraries to solve this.

See gohugoio/hugo#874

@cespare
Copy link
Contributor

cespare commented Mar 31, 2016

Probably a dup of #10123 or one of the previous issues discussing this.

A big external library is not required. One way you can handle this is by providing your own ResponseWriter which spits out your custom page after it sees WriteHeader(404).

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 31, 2016
@ianlancetaylor ianlancetaylor changed the title html: FileServer should provide a way to show a error page on 404 net/http: FileServer should provide a way to show a error page on 404 Mar 31, 2016
@bep
Copy link
Contributor Author

bep commented Apr 1, 2016

A big external library is not required.

I was just quoting several people who have tried to solve this issue in a clean way in the built-in dev file server in Hugo. I haven't looked into this my self, but if the "common Go developer" are having a hard time cracking this nut, you should consider to help him/her.

@hansrodtang
Copy link

A quick and dirty proof-of-concept.
It should be pretty simple to implement your own handler in a similar way.

@bep
Copy link
Contributor Author

bep commented Apr 2, 2016

It should be pretty simple to implement your own handler in a similar way.

Sure, but this is still 50ish lines of code that every person (I know, not every ...) who wants to use the FileServer must implement. You added the FileServer abstraction at one point, so you might as well finish it. Where to stop, you might ask, and that is a good question. A unified way of handling the most common error situation, a file that doesn't exist, is well within the borders.

@bradfitz bradfitz changed the title net/http: FileServer should provide a way to show a error page on 404 net/http/httputil: add a custom-error-page ResponseWriter wrapper type Apr 10, 2016
@bradfitz bradfitz modified the milestones: Go1.7, Unplanned Apr 10, 2016
@bradfitz bradfitz self-assigned this Apr 10, 2016
@bradfitz bradfitz modified the milestones: Go1.8Maybe, Go1.7 May 10, 2016
@bradfitz bradfitz removed their assignment May 10, 2016
@gkop
Copy link

gkop commented Aug 12, 2016

It would be nice if we could handle things other than status code, for example timeouts. In the meantime we're using https://github.com/vulcand/oxy , which provides error handling in its reverse proxy.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@rsc
Copy link
Contributor

rsc commented Oct 20, 2016

Dup of #10123.

@rsc rsc closed this as completed Oct 20, 2016
@golang golang locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

9 participants