summaryrefslogtreecommitdiffstats
path: root/llgo/third_party/gofrontend/libgo/go/cmd/go/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'llgo/third_party/gofrontend/libgo/go/cmd/go/http.go')
-rw-r--r--llgo/third_party/gofrontend/libgo/go/cmd/go/http.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/llgo/third_party/gofrontend/libgo/go/cmd/go/http.go b/llgo/third_party/gofrontend/libgo/go/cmd/go/http.go
index 107b820f28c..7979c41b11b 100644
--- a/llgo/third_party/gofrontend/libgo/go/cmd/go/http.go
+++ b/llgo/third_party/gofrontend/libgo/go/cmd/go/http.go
@@ -18,11 +18,25 @@ import (
"log"
"net/http"
"net/url"
+ "time"
)
// httpClient is the default HTTP client, but a variable so it can be
// changed by tests, without modifying http.DefaultClient.
var httpClient = http.DefaultClient
+var impatientHTTPClient = &http.Client{
+ Timeout: time.Duration(5 * time.Second),
+}
+
+type httpError struct {
+ status string
+ statusCode int
+ url string
+}
+
+func (e *httpError) Error() string {
+ return fmt.Sprintf("%s: %s", e.url, e.status)
+}
// httpGET returns the data from an HTTP GET request for the given URL.
func httpGET(url string) ([]byte, error) {
@@ -32,7 +46,9 @@ func httpGET(url string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return nil, fmt.Errorf("%s: %s", url, resp.Status)
+ err := &httpError{status: resp.Status, statusCode: resp.StatusCode, url: url}
+
+ return nil, err
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
@@ -43,7 +59,7 @@ func httpGET(url string) ([]byte, error) {
// httpsOrHTTP returns the body of either the importPath's
// https resource or, if unavailable, the http resource.
-func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err error) {
+func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body io.ReadCloser, err error) {
fetch := func(scheme string) (urlStr string, res *http.Response, err error) {
u, err := url.Parse(scheme + "://" + importPath)
if err != nil {
@@ -54,7 +70,11 @@ func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err erro
if buildV {
log.Printf("Fetching %s", urlStr)
}
- res, err = httpClient.Get(urlStr)
+ if security == insecure && scheme == "https" { // fail earlier
+ res, err = impatientHTTPClient.Get(urlStr)
+ } else {
+ res, err = httpClient.Get(urlStr)
+ }
return
}
closeBody := func(res *http.Response) {
@@ -72,7 +92,9 @@ func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err erro
}
}
closeBody(res)
- urlStr, res, err = fetch("http")
+ if security == insecure {
+ urlStr, res, err = fetch("http")
+ }
}
if err != nil {
closeBody(res)
OpenPOWER on IntegriCloud