Browse Source

deliver init header to complete in upload

master
jojoliang 4 years ago
parent
commit
f398b20eee
  1. 2
      cos.go
  2. 32
      helper.go
  3. 1
      object.go

2
cos.go

@ -22,7 +22,7 @@ import (
const (
// Version current go sdk version
Version = "0.7.24"
Version = "0.7.25"
userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"

32
helper.go

@ -6,6 +6,7 @@ import (
"crypto/sha1"
"errors"
"fmt"
"github.com/mozillazg/go-httpheader"
"hash/crc64"
"io"
"net/http"
@ -260,3 +261,34 @@ func FormatRangeOptions(opt *RangeOptions) string {
}
return "bytes=-"
}
var deliverHeader = map[string]bool{}
func isDeliverHeader(key string) bool {
for k, v := range deliverHeader {
if key == k && v {
return true
}
}
return strings.HasPrefix(key, privateHeaderPrefix)
}
func deliverInitOptions(opt *InitiateMultipartUploadOptions) (*http.Header, error) {
if opt == nil {
return nil, nil
}
h, err := httpheader.Header(opt)
if err != nil {
return nil, err
}
header := &http.Header{}
for key, values := range h {
key = strings.ToLower(key)
if isDeliverHeader(key) {
for _, value := range values {
header.Add(key, value)
}
}
}
return header, nil
}

1
object.go

@ -914,6 +914,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
var consumedBytes int64
if opt.OptIni != nil {
listener = opt.OptIni.Listener
optcom.XOptionHeader, _ = deliverInitOptions(opt.OptIni)
}
event := newProgressEvent(ProgressStartedEvent, 0, 0, totalBytes)
progressCallback(listener, event)

Loading…
Cancel
Save