You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current implementation of httputil.ReverseProxy is pretty handy and useful,
however there's one small issue with error handling: there's no easy way to
override or customize error response.
Perhaps having a error handler func on ReverseProxy struct might be a good idea:
typeReverseProxystruct {
// ... existing code ...// Handler function that will be invoked when proxy request fails due to // various reasons (timeout, connection refused, etc)ErrorHandlerfunc(error, http.ResponseWriter,*http.Request)
}
If ErrorHandler is not provided proxy will keep the existing behavior, otherwise
it'll pass error handling to our custom function.
Example:
proxy:=httputil.NewSingleHostReverseProxy(target)
proxy.ErrorHandler=func(errerror, w http.ResponseWriter, r*http.Request) {
// check error type and do something// ....// respond with some other status codew.WriteHeader(http.StatusServiceUnavailable)
}
Any thoughts?
The text was updated successfully, but these errors were encountered:
Current implementation of
httputil.ReverseProxy
is pretty handy and useful,however there's one small issue with error handling: there's no easy way to
override or customize error response.
Here's the current error handling code:
Perhaps having a error handler func on
ReverseProxy
struct might be a good idea:If
ErrorHandler
is not provided proxy will keep the existing behavior, otherwiseit'll pass error handling to our custom function.
Example:
Any thoughts?
The text was updated successfully, but these errors were encountered: