Remove pre go1.8 code and cleanup (#4933)

We don't need certain go1.7.x custom code anymore, since
we have migrated to go1.8
This commit is contained in:
Harshavardhana 2017-09-22 14:03:31 -07:00 committed by Dee Koder
parent 6d7df1d1cb
commit 330f79b40e
2 changed files with 14 additions and 44 deletions

View File

@ -111,7 +111,7 @@ func lookupEndpoint(urlStr string) error {
client := &http.Client{ client := &http.Client{
Timeout: 1 * time.Second, Timeout: 1 * time.Second,
Transport: &http.Transport{ Transport: &http.Transport{
// need to close connection after usage. // Need to close connection after usage.
DisableKeepAlives: true, DisableKeepAlives: true,
}, },
} }
@ -122,50 +122,20 @@ func lookupEndpoint(urlStr string) error {
// Set proper server user-agent. // Set proper server user-agent.
req.Header.Set("User-Agent", globalServerUserAgent) req.Header.Set("User-Agent", globalServerUserAgent)
// Retry if the request needs to be re-directed. resp, err := client.Do(req)
// This code is necessary since Go 1.7.x do not if err != nil {
// support retrying for http 307 for POST operation. if isNetErrorIgnored(err) {
// https://github.com/golang/go/issues/7912 errorIf(err, "Unable to lookup webhook endpoint %s", urlStr)
// return nil
// FIXME: Remove this when we move to Go 1.8.
for {
resp, derr := client.Do(req)
if derr != nil {
if isNetErrorIgnored(derr) {
errorIf(derr, "Unable to lookup webhook endpoint %s", urlStr)
return nil
}
return derr
} }
if resp == nil { return err
return fmt.Errorf("No response from server to download URL %s", urlStr)
}
resp.Body.Close()
// Redo the request with the new redirect url if http 307
// is returned, quit the loop otherwise
if resp.StatusCode == http.StatusTemporaryRedirect {
newURL, uerr := url.Parse(resp.Header.Get("Location"))
if uerr != nil {
return uerr
}
req.URL = newURL
continue
}
// For any known successful http status, return quickly.
for _, httpStatus := range successStatus {
if httpStatus == resp.StatusCode {
return nil
}
}
err = fmt.Errorf("Unexpected response from webhook server %s: (%s)", urlStr, resp.Status)
break
} }
defer resp.Body.Close()
// Succes. // HTTP status OK/NoContent.
return err if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("Unable to lookup webhook endpoint %s response(%s)", urlStr, resp.Status)
}
return nil
} }
// Initializes new webhook logrus notifier. // Initializes new webhook logrus notifier.

View File

@ -106,7 +106,7 @@ func TestLookupEndpoint(t *testing.T) {
}, },
{ {
endpoint: server.URL, endpoint: server.URL,
err: fmt.Errorf("Unexpected response from webhook server %s: (400 Bad Request)", server.URL), err: fmt.Errorf("Unable to lookup webhook endpoint %s response(400 Bad Request)", server.URL),
}, },
} }
for _, test := range testCases { for _, test := range testCases {