Skip to content

Commit 2fc78aa

Browse files
author
jojoliang
committed
update bucket policy sign content-length
1 parent 1f1f7c2 commit 2fc78aa

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

bucket_policy.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,24 @@ type BucketGetPolicyResult BucketPutPolicyOptions
2727

2828
func (s *BucketService) PutPolicy(ctx context.Context, opt *BucketPutPolicyOptions) (*Response, error) {
2929
var f *strings.Reader
30+
var body string
3031
if opt != nil {
3132
bs, err := json.Marshal(opt)
3233
if err != nil {
3334
return nil, err
3435
}
35-
body := string(bs)
36+
body = string(bs)
3637
f = strings.NewReader(body)
3738
}
39+
header := &commonHeader{
40+
ContentLength: int64(len(body)),
41+
}
3842
sendOpt := &sendOptions{
39-
baseURL: s.client.BaseURL.BucketURL,
40-
uri: "/?policy",
41-
method: http.MethodPut,
42-
body: f,
43+
baseURL: s.client.BaseURL.BucketURL,
44+
uri: "/?policy",
45+
method: http.MethodPut,
46+
body: f,
47+
optHeader: header,
4348
}
4449
resp, err := s.client.send(ctx, sendOpt)
4550
return resp, err

cos.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ func (c *Client) GetCredential() *Credential {
267267
return nil
268268
}
269269

270+
type commonHeader struct {
271+
ContentLength int64 `header:"Content-Length,omitempty"`
272+
}
273+
270274
func (c *Client) newPresignedRequest(ctx context.Context, sendOpt *sendOptions) (req *http.Request, err error) {
271275
sendOpt.uri, err = addURLOptions(sendOpt.uri, sendOpt.optQuery)
272276
if err != nil {

0 commit comments

Comments
 (0)