mirror of https://github.com/statping/statping
				
				
				
			force dialer to connect the host specified in req.URL.Host not in req.Host!
							parent
							
								
									d9cf4c769a
								
							
						
					
					
						commit
						bd58f3c747
					
				| 
						 | 
					@ -16,6 +16,7 @@
 | 
				
			||||||
package utils
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
	"crypto/tls"
 | 
						"crypto/tls"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
| 
						 | 
					@ -24,6 +25,7 @@ import (
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"math"
 | 
						"math"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
| 
						 | 
					@ -298,6 +300,11 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var resp *http.Response
 | 
						var resp *http.Response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dialer := &net.Dialer{
 | 
				
			||||||
 | 
							Timeout:   30 * time.Second,
 | 
				
			||||||
 | 
							KeepAlive: 30 * time.Second,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	transport := &http.Transport{
 | 
						transport := &http.Transport{
 | 
				
			||||||
		TLSClientConfig: &tls.Config{
 | 
							TLSClientConfig: &tls.Config{
 | 
				
			||||||
			InsecureSkipVerify: !verifySSL,
 | 
								InsecureSkipVerify: !verifySSL,
 | 
				
			||||||
| 
						 | 
					@ -307,6 +314,11 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
 | 
				
			||||||
		ResponseHeaderTimeout: timeout,
 | 
							ResponseHeaderTimeout: timeout,
 | 
				
			||||||
		TLSHandshakeTimeout:   timeout,
 | 
							TLSHandshakeTimeout:   timeout,
 | 
				
			||||||
		Proxy:                 http.ProxyFromEnvironment,
 | 
							Proxy:                 http.ProxyFromEnvironment,
 | 
				
			||||||
 | 
							DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
								// redirect all connections to host specified in url
 | 
				
			||||||
 | 
								addr = req.URL.Host
 | 
				
			||||||
 | 
								return dialer.DialContext(ctx, network, addr)
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	client := &http.Client{
 | 
						client := &http.Client{
 | 
				
			||||||
		Transport: transport,
 | 
							Transport: transport,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue