1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
16 "git.arvados.org/arvados.git/sdk/go/arvados"
23 // URL where the proxy is listening. Same as Server.URL, but
24 // with parsing already done for you.
27 // A dump of each request that has been proxied.
31 // NewProxy returns a new Proxy that saves a dump of each reqeust
32 // before forwarding to the indicated service.
33 func NewProxy(c *check.C, svc arvados.Service) *Proxy {
35 c.Assert(svc.InternalURLs, check.HasLen, 1)
36 for u := range svc.InternalURLs {
40 rp := httputil.NewSingleHostReverseProxy(&target)
41 rp.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
42 dump, _ := httputil.DumpRequest(r, false)
43 c.Logf("arvadostest.Proxy ErrorHandler(%s): %s\n%s", r.URL, err, dump)
44 http.Error(w, err.Error(), http.StatusBadGateway)
46 rp.Transport = &http.Transport{
47 DialContext: (&net.Dialer{
48 Timeout: 30 * time.Second,
49 KeepAlive: 30 * time.Second,
53 IdleConnTimeout: 90 * time.Second,
54 TLSHandshakeTimeout: 10 * time.Second,
55 ExpectContinueTimeout: 1 * time.Second,
56 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
58 srv := httptest.NewServer(rp)
59 u, err := url.Parse(srv.URL)
60 c.Assert(err, check.IsNil)
65 rp.Director = func(r *http.Request) {
66 dump, _ := httputil.DumpRequest(r, true)
67 proxy.RequestDumps = append(proxy.RequestDumps, dump)
68 r.URL.Scheme = target.Scheme
69 r.URL.Host = target.Host