Skip to content

Commit

Permalink
update bucket policy sign content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoliang committed Feb 24, 2025
1 parent 1f1f7c2 commit 2fc78aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bucket_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ type BucketGetPolicyResult BucketPutPolicyOptions

func (s *BucketService) PutPolicy(ctx context.Context, opt *BucketPutPolicyOptions) (*Response, error) {
var f *strings.Reader
var body string
if opt != nil {
bs, err := json.Marshal(opt)
if err != nil {
return nil, err
}
body := string(bs)
body = string(bs)
f = strings.NewReader(body)
}
header := &commonHeader{
ContentLength: int64(len(body)),
}
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?policy",
method: http.MethodPut,
body: f,
baseURL: s.client.BaseURL.BucketURL,
uri: "/?policy",
method: http.MethodPut,
body: f,
optHeader: header,
}
resp, err := s.client.send(ctx, sendOpt)
return resp, err
Expand Down
4 changes: 4 additions & 0 deletions cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ func (c *Client) GetCredential() *Credential {
return nil
}

type commonHeader struct {
ContentLength int64 `header:"Content-Length,omitempty"`
}

func (c *Client) newPresignedRequest(ctx context.Context, sendOpt *sendOptions) (req *http.Request, err error) {
sendOpt.uri, err = addURLOptions(sendOpt.uri, sendOpt.optQuery)
if err != nil {
Expand Down

0 comments on commit 2fc78aa

Please sign in to comment.