Merge pull request #144 from harshavardhana/pr_out_move_s3errors_and_make_it_part_of_standard_s3_package

This commit is contained in:
Harshavardhana
2015-03-19 00:17:08 -07:00
4 changed files with 33 additions and 16 deletions
+23 -1
View File
@@ -215,7 +215,28 @@ func (a *Auth) writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request
}
// Must be sorted:
var subResList = []string{"acl", "lifecycle", "location", "logging", "notification", "partNumber", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId", "versioning", "versions", "website"}
var subResList = []string{
"acl",
"location",
"logging",
"notification",
"partNumber",
"policy",
"requestPayment",
"torrent",
"uploadId",
"uploads",
"versionId",
"versioning",
"versions",
"response-content-type",
"response-content-language",
"response-expires",
"response-cache-control",
"response-content-disposition",
"response-content-encoding",
"website",
}
// From the Amazon docs:
//
@@ -229,6 +250,7 @@ func (a *Auth) writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request,
buf.WriteString(bucket)
}
buf.WriteString(req.URL.Path)
sort.Strings(subResList)
if req.URL.RawQuery != "" {
n := 0
vals, _ := url.ParseQuery(req.URL.RawQuery)
+3 -5
View File
@@ -50,8 +50,6 @@ import (
"encoding/xml"
"net/http"
"net/url"
"github.com/minio-io/mc/pkg/s3errors"
)
// bySize implements sort.Interface for []Item based on the Size field.
@@ -76,7 +74,7 @@ func (c *Client) ListBuckets() ([]*Bucket, error) {
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, s3errors.New(res)
return nil, NewError(res)
}
return parseListAllMyBuckets(res.Body)
@@ -98,7 +96,7 @@ func (c *Client) PutBucket(bucket string) error {
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return s3errors.New(res)
return NewError(res)
}
return nil
@@ -154,7 +152,7 @@ func (c *Client) ListObjects(bucket string, startAt, prefix, delimiter string, m
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, nil, s3errors.New(res)
return nil, nil, NewError(res)
}
bres = listBucketResults{}
+3 -4
View File
@@ -14,8 +14,7 @@
* limitations under the License.
*/
// Package s3errors implements client side error handling for S3 protocol
package s3errors
package s3
import (
"fmt"
@@ -42,8 +41,8 @@ type Error struct {
resMsg mxj.Map // Keys: Code, Message, Resource, RequestId, HostId
}
// New returns a new initialized S3.Error structure
func New(res *http.Response) error {
// NewError returns a new initialized S3.Error structure
func NewError(res *http.Response) error {
var err error
var s3Err Error
+4 -6
View File
@@ -51,8 +51,6 @@ import (
"encoding/base64"
"io/ioutil"
"net/http"
"github.com/minio-io/mc/pkg/s3errors"
)
/// Object API operations
@@ -86,7 +84,7 @@ func (c *Client) Put(bucket, key string, size int64, contents io.Reader) error {
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return s3errors.New(res)
return NewError(res)
}
return nil
}
@@ -119,7 +117,7 @@ func (c *Client) Stat(bucket, key string) (size int64, date time.Time, reterr er
return size, date, nil
}
default:
return 0, date, s3errors.New(res)
return 0, date, NewError(res)
}
return
}
@@ -134,7 +132,7 @@ func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err er
}
if res.StatusCode != http.StatusOK {
return nil, 0, s3errors.New(res)
return nil, 0, NewError(res)
}
return res.Body, res.ContentLength, nil
@@ -164,6 +162,6 @@ func (c *Client) GetPartial(bucket, key string, offset, length int64) (body io.R
case http.StatusOK, http.StatusPartialContent:
return res.Body, res.ContentLength, nil
default:
return nil, 0, s3errors.New(res)
return nil, 0, NewError(res)
}
}