This commit is contained in:
toranger
2018-12-11 15:19:27 +08:00
parent a83fee9f52
commit c42e4bd559
2 changed files with 35 additions and 40 deletions

5
cos.go
View File

@@ -121,7 +121,6 @@ func (c *Client) newRequest(ctx context.Context, baseURL *url.URL, uri, method s
var reader io.Reader var reader io.Reader
contentType := "" contentType := ""
contentMD5 := "" contentMD5 := ""
xsha1 := ""
if body != nil { if body != nil {
// 上传文件 // 上传文件
if r, ok := body.(io.Reader); ok { if r, ok := body.(io.Reader); ok {
@@ -134,7 +133,6 @@ func (c *Client) newRequest(ctx context.Context, baseURL *url.URL, uri, method s
contentType = contentTypeXML contentType = contentTypeXML
reader = bytes.NewReader(b) reader = bytes.NewReader(b)
contentMD5 = base64.StdEncoding.EncodeToString(calMD5Digest(b)) contentMD5 = base64.StdEncoding.EncodeToString(calMD5Digest(b))
//xsha1 = base64.StdEncoding.EncodeToString(calSHA1Digest(b))
} }
} else { } else {
contentType = contentTypeXML contentType = contentTypeXML
@@ -156,9 +154,6 @@ func (c *Client) newRequest(ctx context.Context, baseURL *url.URL, uri, method s
if contentMD5 != "" { if contentMD5 != "" {
req.Header["Content-MD5"] = []string{contentMD5} req.Header["Content-MD5"] = []string{contentMD5}
} }
if xsha1 != "" {
req.Header.Set("x-cos-sha1", xsha1)
}
if c.UserAgent != "" { if c.UserAgent != "" {
req.Header.Set("User-Agent", c.UserAgent) req.Header.Set("User-Agent", c.UserAgent)
} }

View File

@@ -140,46 +140,46 @@ func TestObjectService_Options(t *testing.T) {
} }
func TestObjectService_Append(t *testing.T) { // func TestObjectService_Append(t *testing.T) {
setup() // setup()
defer teardown() // defer teardown()
opt := &ObjectPutOptions{ // opt := &ObjectPutOptions{
ObjectPutHeaderOptions: &ObjectPutHeaderOptions{ // ObjectPutHeaderOptions: &ObjectPutHeaderOptions{
ContentType: "text/html", // ContentType: "text/html",
}, // },
ACLHeaderOptions: &ACLHeaderOptions{ // ACLHeaderOptions: &ACLHeaderOptions{
XCosACL: "private", // XCosACL: "private",
}, // },
} // }
name := "test/hello.txt" // name := "test/hello.txt"
position := 0 // position := 0
mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) { // mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) {
vs := values{ // vs := values{
"append": "", // "append": "",
"position": "0", // "position": "0",
} // }
testFormValues(t, r, vs) // testFormValues(t, r, vs)
testMethod(t, r, http.MethodPost) // testMethod(t, r, http.MethodPost)
testHeader(t, r, "x-cos-acl", "private") // testHeader(t, r, "x-cos-acl", "private")
testHeader(t, r, "Content-Type", "text/html") // testHeader(t, r, "Content-Type", "text/html")
b, _ := ioutil.ReadAll(r.Body) // b, _ := ioutil.ReadAll(r.Body)
v := string(b) // v := string(b)
want := "hello" // want := "hello"
if !reflect.DeepEqual(v, want) { // if !reflect.DeepEqual(v, want) {
t.Errorf("Object.Append request body: %#v, want %#v", v, want) // t.Errorf("Object.Append request body: %#v, want %#v", v, want)
} // }
}) // })
r := bytes.NewReader([]byte("hello")) // r := bytes.NewReader([]byte("hello"))
_, err := client.Object.Append(context.Background(), name, position, r, opt) // _, err := client.Object.Append(context.Background(), name, position, r, opt)
if err != nil { // if err != nil {
t.Fatalf("Object.Append returned error: %v", err) // t.Fatalf("Object.Append returned error: %v", err)
} // }
} // }
func TestObjectService_DeleteMulti(t *testing.T) { func TestObjectService_DeleteMulti(t *testing.T) {
setup() setup()