Browse Source

Add options to skip tls verification

This corresponds to https://golang.org/cl/33157
Raul Silvera 8 years ago
parent
commit
6960e0b9a3
1 changed files with 19 additions and 3 deletions
  1. 19
    3
      internal/driver/fetch.go

+ 19
- 3
internal/driver/fetch.go View File

@@ -16,6 +16,7 @@ package driver
16 16
 
17 17
 import (
18 18
 	"bytes"
19
+	"crypto/tls"
19 20
 	"fmt"
20 21
 	"io"
21 22
 	"net/http"
@@ -474,12 +475,27 @@ func adjustURL(source string, duration, timeout time.Duration) (string, time.Dur
474 475
 
475 476
 // httpGet is a wrapper around http.Get; it is defined as a variable
476 477
 // so it can be redefined during for testing.
477
-var httpGet = func(url string, timeout time.Duration) (*http.Response, error) {
478
+var httpGet = func(source string, timeout time.Duration) (*http.Response, error) {
479
+	url, err := url.Parse(source)
480
+	if err != nil {
481
+		return nil, err
482
+	}
483
+
484
+	var tlsConfig *tls.Config
485
+	if url.Scheme == "https+insecure" {
486
+		tlsConfig = &tls.Config{
487
+			InsecureSkipVerify: true,
488
+		}
489
+		url.Scheme = "https"
490
+		source = url.String()
491
+	}
492
+
478 493
 	client := &http.Client{
479 494
 		Transport: &http.Transport{
480 495
 			ResponseHeaderTimeout: timeout + 5*time.Second,
481
-			Proxy: http.ProxyFromEnvironment,
496
+			Proxy:           http.ProxyFromEnvironment,
497
+			TLSClientConfig: tlsConfig,
482 498
 		},
483 499
 	}
484
-	return client.Get(url)
500
+	return client.Get(source)
485 501
 }