mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
go1.8: Changes to support golang 1.8 (#4759)
QuirkConn is added to replace net.Conn as a workaround to a golang bug: https://github.com/golang/go/issues/21133
This commit is contained in:
committed by
Harshavardhana
parent
218049300c
commit
b4dc6df35c
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -33,9 +32,6 @@ func TestNewEndpoint(t *testing.T) {
|
||||
u4, _ := url.Parse("http://192.168.253.200/path")
|
||||
|
||||
errMsg := ": no such host"
|
||||
if runtime.GOOS == "windows" {
|
||||
errMsg = ": No such host is known."
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
arg string
|
||||
@@ -232,7 +228,7 @@ func TestCreateEndpoints(t *testing.T) {
|
||||
expectedSetupType SetupType
|
||||
expectedErr error
|
||||
}{
|
||||
{"localhost", []string{}, "", EndpointList{}, -1, fmt.Errorf("missing port in address localhost")},
|
||||
{"localhost", []string{}, "", EndpointList{}, -1, fmt.Errorf("address localhost: missing port in address")},
|
||||
|
||||
// FS Setup
|
||||
{"localhost:9000", []string{"http://localhost/d1"}, "", EndpointList{}, -1, fmt.Errorf("use path style endpoint for FS setup")},
|
||||
|
||||
16
cmd/net.go
16
cmd/net.go
@@ -198,18 +198,20 @@ func extractHostPort(hostAddr string) (string, string, error) {
|
||||
return "", "", errors.New("unable to process empty address")
|
||||
}
|
||||
|
||||
// Simplify the work of url.Parse() and always send a url with
|
||||
if !strings.HasPrefix(hostAddr, "http://") && !strings.HasPrefix(hostAddr, "https://") {
|
||||
hostAddr = "//" + hostAddr
|
||||
}
|
||||
|
||||
// Parse address to extract host and scheme field
|
||||
u, err := url.Parse(hostAddr)
|
||||
if err != nil {
|
||||
// Ignore scheme not present error
|
||||
if !strings.Contains(err.Error(), "missing protocol scheme") {
|
||||
return "", "", err
|
||||
}
|
||||
} else {
|
||||
addr = u.Host
|
||||
scheme = u.Scheme
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
addr = u.Host
|
||||
scheme = u.Scheme
|
||||
|
||||
// Use the given parameter again if url.Parse()
|
||||
// didn't return any useful result.
|
||||
if addr == "" {
|
||||
|
||||
@@ -223,7 +223,7 @@ func TestCheckLocalServerAddr(t *testing.T) {
|
||||
{"localhost:54321", nil},
|
||||
{"0.0.0.0:9000", nil},
|
||||
{"", fmt.Errorf("missing port in address")},
|
||||
{"localhost", fmt.Errorf("missing port in address localhost")},
|
||||
{"localhost", fmt.Errorf("address localhost: missing port in address")},
|
||||
{"example.org:54321", fmt.Errorf("host in server address should be this server")},
|
||||
{":0", fmt.Errorf("port number must be between 1 to 65535")},
|
||||
{":-10", fmt.Errorf("port number must be between 1 to 65535")},
|
||||
@@ -251,7 +251,6 @@ func TestExtractHostPort(t *testing.T) {
|
||||
expectedErr error
|
||||
}{
|
||||
{"", "", "", errors.New("unable to process empty address")},
|
||||
{"localhost", "localhost", "80", nil},
|
||||
{"localhost:9000", "localhost", "9000", nil},
|
||||
{"http://:9000/", "", "9000", nil},
|
||||
{"http://8.8.8.8:9000/", "8.8.8.8", "9000", nil},
|
||||
@@ -294,7 +293,9 @@ func TestSameLocalAddrs(t *testing.T) {
|
||||
{":9000", ":9000", true, nil},
|
||||
{"localhost:9000", ":9000", true, nil},
|
||||
{"localhost:9000", "http://localhost:9000", true, nil},
|
||||
{"8.8.8.8:9000", "http://localhost:9000", false, nil},
|
||||
{"http://localhost:9000", ":9000", true, nil},
|
||||
{"http://localhost:9000", "http://localhost:9000", true, nil},
|
||||
{"http://8.8.8.8:9000", "http://localhost:9000", false, nil},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestNewWebHookNotify(t *testing.T) {
|
||||
t.Fatal("Unexpected should fail")
|
||||
}
|
||||
|
||||
serverConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: "http://127.0.0.1:xxx"})
|
||||
serverConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: "http://127.0.0.1:80"})
|
||||
_, err = newWebhookNotify("10")
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected should not fail with lookupEndpoint", err)
|
||||
|
||||
@@ -939,14 +939,10 @@ func signRequestV2(req *http.Request, accessKey, secretKey string) error {
|
||||
req.Header.Set("Date", d.Format(http.TimeFormat))
|
||||
}
|
||||
|
||||
// url.RawPath will be valid if path has any encoded characters, if not it will
|
||||
// be empty - in which case we need to consider url.Path (bug in net/http?)
|
||||
encodedResource := req.URL.RawPath
|
||||
if encodedResource == "" {
|
||||
splits := strings.Split(req.URL.Path, "?")
|
||||
if len(splits) > 0 {
|
||||
encodedResource = getURLEncodedName(splits[0])
|
||||
}
|
||||
splits := strings.Split(req.URL.Path, "?")
|
||||
var encodedResource string
|
||||
if len(splits) > 0 {
|
||||
encodedResource = getURLEncodedName(splits[0])
|
||||
}
|
||||
encodedQuery := req.URL.Query().Encode()
|
||||
|
||||
@@ -1088,16 +1084,9 @@ func newTestRequest(method, urlStr string, contentLength int64, body io.ReadSeek
|
||||
method = "POST"
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, urlStr, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add Content-Length
|
||||
req.ContentLength = contentLength
|
||||
|
||||
// Save for subsequent use
|
||||
var hashedPayload string
|
||||
var md5Base64 string
|
||||
switch {
|
||||
case body == nil:
|
||||
hashedPayload = getSHA256Hash([]byte{})
|
||||
@@ -1107,21 +1096,25 @@ func newTestRequest(method, urlStr string, contentLength int64, body io.ReadSeek
|
||||
return nil, err
|
||||
}
|
||||
hashedPayload = getSHA256Hash(payloadBytes)
|
||||
md5Base64 := getMD5HashBase64(payloadBytes)
|
||||
req.Header.Set("Content-Md5", md5Base64)
|
||||
md5Base64 = getMD5HashBase64(payloadBytes)
|
||||
}
|
||||
req.Header.Set("x-amz-content-sha256", hashedPayload)
|
||||
// Seek back to beginning.
|
||||
if body != nil {
|
||||
body.Seek(0, 0)
|
||||
// Add body
|
||||
req.Body = ioutil.NopCloser(body)
|
||||
} else {
|
||||
// this is added to avoid panic during ioutil.ReadAll(req.Body).
|
||||
// th stack trace can be found here https://github.com/minio/minio/pull/2074 .
|
||||
// This is very similar to https://github.com/golang/go/issues/7527.
|
||||
req.Body = ioutil.NopCloser(bytes.NewReader([]byte("")))
|
||||
body = bytes.NewReader([]byte(""))
|
||||
}
|
||||
req, err := http.NewRequest(method, urlStr, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if md5Base64 != "" {
|
||||
req.Header.Set("Content-Md5", md5Base64)
|
||||
}
|
||||
req.Header.Set("x-amz-content-sha256", hashedPayload)
|
||||
|
||||
// Add Content-Length
|
||||
req.ContentLength = contentLength
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user