Commit 0fa72053 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Map all HTTP errors to 502

parent b0452381
......@@ -113,7 +113,8 @@ func main() {
log.Fatal(err)
}
var authTransport http.RoundTripper
// Create Proxy Transport
authTransport := http.DefaultTransport
if *authSocket != "" {
dialer := &net.Dialer{
// The values below are taken from http.DefaultTransport
......@@ -126,6 +127,7 @@ func main() {
},
}
}
proxyTransport := &proxyRoundTripper{transport: authTransport}
// The profiler will only be activated by HTTP requests. HTTP
// requests can only reach the profiler if we start a listener. So by
......@@ -137,7 +139,7 @@ func main() {
}()
}
upstream := newUpstream(*authBackend, authTransport)
upstream := newUpstream(*authBackend, proxyTransport)
upstream.SetRelativeUrlRoot(*relativeUrlRoot)
upstream.SetProxyTimeout(*proxyTimeout)
......
package main
import (
"bytes"
"io/ioutil"
"net/http"
)
type proxyRoundTripper struct {
transport http.RoundTripper
}
func (p *proxyRoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error) {
res, err = p.transport.RoundTrip(r)
// Map error to 502 response
if err != nil {
res = &http.Response{
StatusCode: 502,
Status: err.Error(),
Request: r,
ProtoMajor: r.ProtoMajor,
ProtoMinor: r.ProtoMinor,
Proto: r.Proto,
Header: make(http.Header),
Trailer: make(http.Header),
Body: ioutil.NopCloser(&bytes.Buffer{}),
}
err = nil
}
return
}
func headerClone(h http.Header) http.Header {
h2 := make(http.Header, len(h))
for k, vv := range h {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment