Skip to content

Commit

Permalink
wip: disable TLS verification temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Aug 21, 2019
1 parent fce9b0c commit dc173db
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions proxy/http.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package proxy

import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"strings"
"time"

"github.com/pact-foundation/pact-go/utils"
)
Expand Down Expand Up @@ -76,6 +79,7 @@ func HTTPReverseProxy(options Options) (int, error) {
Path: options.TargetPath,
}
proxy := createProxy(url, options.InternalRequestPathPrefix)
proxy.Transport = debugTransport{}

if port == 0 {
port, err = utils.GetFreePort()
Expand All @@ -93,6 +97,41 @@ func HTTPReverseProxy(options Options) (int, error) {
return port, nil
}

// https://stackoverflow.com/questions/52986853/how-to-debug-httputil-newsinglehostreverseproxy
// Set the proxy.Transport field to an implementation that dumps the request before delegating to the default transport:

type debugTransport struct{}

func (debugTransport) RoundTrip(r *http.Request) (*http.Response, error) {
b, err := httputil.DumpRequestOut(r, false)
if err != nil {
return nil, err
}
log.Println("[TRACE] proxy outgoing request\n", string(b))

var DefaultTransport http.RoundTripper = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}

res, err := DefaultTransport.RoundTrip(r)
b, err = httputil.DumpResponse(res, false)
log.Println("[TRACE] proxied server response\n", string(b))

return res, err
}

// Adapted from https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go
func createProxy(target *url.URL, ignorePrefix string) *httputil.ReverseProxy {
targetQuery := target.RawQuery
Expand Down

0 comments on commit dc173db

Please sign in to comment.