Fix signature issues, second attempt
This commit is contained in:
Generated
+2
-2
@@ -29,8 +29,8 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio-go",
|
||||
"Comment": "v0.2.0-16-gd4b3d1e",
|
||||
"Rev": "d4b3d1ecfb717775481044e72cc10cc0d534dc0c"
|
||||
"Comment": "v0.2.0-19-g44dd766",
|
||||
"Rev": "44dd766b3563b2f95cc7cf03c4789b28254f3d8a"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio/pkg/probe",
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ func urlEncodeName(name string) (string, error) {
|
||||
continue
|
||||
}
|
||||
switch s {
|
||||
case '-', '_', '.', '~', '/', '+': // §2.3 Unreserved characters (mark)
|
||||
case '-', '_', '.', '~', '/': // §2.3 Unreserved characters (mark)
|
||||
encodedName = encodedName + string(s)
|
||||
continue
|
||||
default:
|
||||
|
||||
+47
-6
@@ -22,6 +22,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -143,6 +144,50 @@ func (op *operation) getRequestURL(config Config) (url string) {
|
||||
return
|
||||
}
|
||||
|
||||
func httpNewRequest(method, urlStr string, body io.Reader) (*http.Request, error) {
|
||||
u, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// make sure to encode properly, url.Parse in golang is buggy and creates erroneous encoding
|
||||
uEncoded := u
|
||||
bucketName, objectName := path2BucketAndObject(uEncoded.Path)
|
||||
if objectName != "" {
|
||||
encodedObjectName, err := urlEncodeName(objectName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uEncoded.Opaque = separator + bucketName + separator + encodedObjectName
|
||||
} else {
|
||||
uEncoded.Opaque = separator + bucketName
|
||||
}
|
||||
rc, ok := body.(io.ReadCloser)
|
||||
if !ok && body != nil {
|
||||
rc = ioutil.NopCloser(body)
|
||||
}
|
||||
req := &http.Request{
|
||||
Method: method,
|
||||
URL: uEncoded,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
Header: make(http.Header),
|
||||
Body: rc,
|
||||
Host: uEncoded.Host,
|
||||
}
|
||||
if body != nil {
|
||||
switch v := body.(type) {
|
||||
case *bytes.Buffer:
|
||||
req.ContentLength = int64(v.Len())
|
||||
case *bytes.Reader:
|
||||
req.ContentLength = int64(v.Len())
|
||||
case *strings.Reader:
|
||||
req.ContentLength = int64(v.Len())
|
||||
}
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// newRequest - instantiate a new request
|
||||
func newRequest(op *operation, config *Config, body io.ReadSeeker) (*request, error) {
|
||||
// if no method default to POST
|
||||
@@ -154,7 +199,7 @@ func newRequest(op *operation, config *Config, body io.ReadSeeker) (*request, er
|
||||
u := op.getRequestURL(*config)
|
||||
|
||||
// get a new HTTP request, for the requested method
|
||||
req, err := http.NewRequest(method, u, nil)
|
||||
req, err := httpNewRequest(method, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -291,13 +336,9 @@ func (r *request) getSignedHeaders() string {
|
||||
//
|
||||
func (r *request) getCanonicalRequest(hashedPayload string) string {
|
||||
r.req.URL.RawQuery = strings.Replace(r.req.URL.Query().Encode(), "+", "%20", -1)
|
||||
encodedPath, _ := urlEncodeName(r.req.URL.Path)
|
||||
// convert any space strings back to "+"
|
||||
encodedPath = strings.Replace(encodedPath, "+", "%20", -1)
|
||||
encodedPath = strings.Replace(encodedPath, "%2B", "+", -1)
|
||||
canonicalRequest := strings.Join([]string{
|
||||
r.req.Method,
|
||||
encodedPath,
|
||||
r.req.URL.Opaque,
|
||||
r.req.URL.RawQuery,
|
||||
r.getCanonicalHeaders(),
|
||||
r.getSignedHeaders(),
|
||||
|
||||
Reference in New Issue
Block a user