Merge branch '15106-trgm-text-search'
[arvados.git] / lib / controller / proxy.go
index b7f3c4f72acf4754884313e44f10793b3bf486ee..c0b94c2b5f76d604e738c2d9bc43d3a01f8bf5dc 100644 (file)
@@ -5,18 +5,15 @@
 package controller
 
 import (
-       "context"
        "io"
        "net/http"
        "net/url"
-       "time"
 
        "git.curoverse.com/arvados.git/sdk/go/httpserver"
 )
 
 type proxy struct {
-       Name           string // to use in Via header
-       RequestTimeout time.Duration
+       Name string // to use in Via header
 }
 
 type HTTPError struct {
@@ -35,6 +32,7 @@ var dropHeaders = map[string]bool{
        "Keep-Alive":          true,
        "Proxy-Authenticate":  true,
        "Proxy-Authorization": true,
+       // this line makes gofmt 1.10 and 1.11 agree
        "TE":                true,
        "Trailer":           true,
        "Transfer-Encoding": true, // *-Encoding headers interfer with Go's automatic compression/decompression
@@ -45,8 +43,8 @@ var dropHeaders = map[string]bool{
 
 type ResponseFilter func(*http.Response, error) (*http.Response, error)
 
-// Forward a request to downstream service, and return response or error.
-func (p *proxy) ForwardRequest(
+// Forward a request to upstream service, and return response or error.
+func (p *proxy) Do(
        reqIn *http.Request,
        urlOut *url.URL,
        client *http.Client) (*http.Response, error) {
@@ -69,23 +67,19 @@ func (p *proxy) ForwardRequest(
        }
        hdrOut.Add("Via", reqIn.Proto+" arvados-controller")
 
-       ctx := reqIn.Context()
-       if p.RequestTimeout > 0 {
-               ctx, _ = context.WithDeadline(ctx, time.Now().Add(time.Duration(p.RequestTimeout)))
-       }
-
        reqOut := (&http.Request{
                Method: reqIn.Method,
                URL:    urlOut,
                Host:   reqIn.Host,
                Header: hdrOut,
                Body:   reqIn.Body,
-       }).WithContext(ctx)
+       }).WithContext(reqIn.Context())
 
-       return client.Do(reqOut)
+       resp, err := client.Do(reqOut)
+       return resp, err
 }
 
-// Copy a response (or error) to the upstream client
+// Copy a response (or error) to the downstream client
 func (p *proxy) ForwardResponse(w http.ResponseWriter, resp *http.Response, err error) (int64, error) {
        if err != nil {
                if he, ok := err.(HTTPError); ok {