Recently while using http.ReverseProxy I wanted to take a specific action if there was a TCP connection failure or other transport-level failure in ReverseProxy.ServerHTTP. However, ReverseProxy.ServeHTTP simply sets a BadGateway status code in this situation, which makes it impossible to differentiate between an actual transport failure and a BadGateway response being returned from the upstream server to which I am proxying.
For context, the action I wanted to take was to restart the backend service return an HTTP redirect to another endpoint. One attempt I made was to write my own Transport wrapper that stored the error, but this didn't work because there was no way to stop the ReverseProxy from still rendering the BadGateway response. After looking at the code, it seems that one could add func (ReverseProxy) TryServeHTTP(w, r) error which would return an error on transport failure, but not on any valid HTTP response from the upstream server. ServerHTTP would then call TryServeHTTP and set a BadGateway if err != nil. I realize there is a high bar for standard library API changes but I just thought I'd throw this out there... Alex -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.