MCPcopy
hub / github.com/fabiolb/fabio / newHTTPProxy

Function newHTTPProxy

proxy/http_handler.go:17–37  ·  view source on GitHub ↗
(target *url.URL, tr http.RoundTripper, flush time.Duration)

Source from the content-addressed store, hash-verified

15const StatusClientClosedRequest = 499
16
17func newHTTPProxy(target *url.URL, tr http.RoundTripper, flush time.Duration) http.Handler {
18 return &httputil.ReverseProxy{
19 // this is a simplified director function based on the
20 // httputil.NewSingleHostReverseProxy() which does not
21 // mangle the request and target URL since the target
22 // URL is already in the correct format.
23 Director: func(req *http.Request) {
24 req.URL.Scheme = target.Scheme
25 req.URL.Host = target.Host
26 req.URL.Path = target.Path
27 req.URL.RawQuery = target.RawQuery
28 if _, ok := req.Header["User-Agent"]; !ok {
29 // explicitly disable User-Agent so it's not set to default value
30 req.Header.Set("User-Agent", "")
31 }
32 },
33 FlushInterval: flush,
34 Transport: tr,
35 ErrorHandler: httpProxyErrorHandler,
36 }
37}
38
39func httpProxyErrorHandler(w http.ResponseWriter, r *http.Request, err error) {
40 // According to https://golang.org/src/net/http/httputil/reverseproxy.go#L74, Go will return a 502 (Bad Gateway) StatusCode by default if no ErrorHandler is provided

Callers 1

ServeHTTPMethod · 0.70

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected