Merge pull request #253 from tufanbarisyildirim/feature/custom-dialer

Feature/custom dialer
pull/242/head^2
Hunter Long 2019-10-15 08:53:53 -07:00 committed by GitHub
commit bbd553c5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,7 @@
package utils
import (
"context"
"crypto/tls"
"errors"
"fmt"
@ -24,6 +25,7 @@ import (
"io/ioutil"
"math"
"math/rand"
"net"
"net/http"
"os"
"os/exec"
@ -298,6 +300,11 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
}
var resp *http.Response
dialer := &net.Dialer{
Timeout: timeout,
KeepAlive: timeout,
}
transport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !verifySSL,
@ -307,6 +314,11 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
ResponseHeaderTimeout: timeout,
TLSHandshakeTimeout: timeout,
Proxy: http.ProxyFromEnvironment,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
// redirect all connections to host specified in url
addr = strings.Split(req.URL.Host, ":")[0] + addr[strings.LastIndex(addr, ":"):]
return dialer.DialContext(ctx, network, addr)
},
}
client := &http.Client{
Transport: transport,