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 Error handler in ReverseProxy #22700

Closed
juliens opened this issue Nov 13, 2017 · 8 comments
Closed

net/http/httputil: add Error handler in ReverseProxy #22700

juliens opened this issue Nov 13, 2017 · 8 comments

Comments

@juliens
Copy link
Contributor

juliens commented Nov 13, 2017

I would love to be able to customize the RoundTrip error handling.
We should be able to change the default behavior that always writes StatusBadGateway.

For example:

statusCode := http.StatusInternalServerError
if e, ok := err.(net.Error); ok {
	if e.Timeout() {
		statusCode = http.StatusGatewayTimeout
	} else {
		statusCode = http.StatusBadGateway
	}
} else if err == io.EOF {
	statusCode = http.StatusBadGateway
}
w.WriteHeader(statusCode)
w.Write([]byte(http.StatusText(statusCode)))
@bradfitz bradfitz changed the title proposal, Error handler in http.ReverseProxy proposal: net/http/httputil: Error handler in ReverseProxy Nov 13, 2017
@gopherbot gopherbot added this to the Proposal milestone Nov 13, 2017
@bradfitz
Copy link
Contributor

Dup of #21255?

There's a pending fix at https://go-review.googlesource.com/c/go/+/54030

@gopherbot
Copy link

Change https://golang.org/cl/77410 mentions this issue: http.ReverseProxy: add an error handler

@odeke-em
Copy link
Member

And CL 77410 has been merged to become commit 5ea2360. Please reopen if that fix doesn't suffice.

Thank you for the proposal/feature-request @juliens and @bradfitz for keeping tabs!

juliens added a commit to juliens/go that referenced this issue Nov 16, 2017
You can specify an ErrorHandler to customize the RoundTrip error
handling.

Fixes golang#22700

Change-Id: I8879f0956e2472a07f584660afa10105ef23bf11
@gopherbot
Copy link

Change https://golang.org/cl/78495 mentions this issue: http.ReverseProxy: add an error handler

@tmthrgd
Copy link
Contributor

tmthrgd commented Jan 6, 2018

@odeke-em should this be reopened since 24df1d0 reverted 5ea2360?

@odeke-em
Copy link
Member

odeke-em commented Jan 6, 2018

Sure, thanks for the vigilance @tmthrgd!

@odeke-em odeke-em reopened this Jan 6, 2018
@rsc
Copy link
Contributor

rsc commented Jan 22, 2018

/cc @tombergan?

@bradfitz
Copy link
Contributor

I like the ErrorHandler approach more than overloading ModifyResponse.

Let's go with a cleaned-up CL 78495. I'll send the minimal edits required.

@bradfitz bradfitz changed the title proposal: net/http/httputil: Error handler in ReverseProxy net/http/httputil: add Error handler in ReverseProxy Jul 13, 2018
@golang golang locked and limited conversation to collaborators Jul 13, 2019
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

6 participants