From 970e24b9c00143cd2dc6363f0ae4f05aa3f5ae60 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 4 Aug 2015 15:12:01 -0700 Subject: [PATCH] Fix signature issues, second attempt --- Godeps/Godeps.json | 4 +- .../src/github.com/minio/minio-go/common.go | 2 +- .../src/github.com/minio/minio-go/request.go | 53 ++++++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index d2232a90..ed4002d8 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -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", diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/common.go b/Godeps/_workspace/src/github.com/minio/minio-go/common.go index 774a544f..6263d559 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/common.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/common.go @@ -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: diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/request.go b/Godeps/_workspace/src/github.com/minio/minio-go/request.go index c24ca850..6c3eebf4 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/request.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/request.go @@ -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(),