Merge pull request #2036 from pyr/fix/sort-v2-headers

v2 signer: correctly sort headers
This commit is contained in:
Richard Scothern 2016-11-10 15:31:24 -08:00 committed by GitHub
commit 6e62b39842

View file

@ -124,6 +124,8 @@ func (v2 *signer) Sign() error {
md5, ctype, date, xamz string md5, ctype, date, xamz string
xamzDate bool xamzDate bool
sarray []string sarray []string
smap map[string]string
sharray []string
) )
headers := v2.Request.Header headers := v2.Request.Header
@ -136,6 +138,7 @@ func (v2 *signer) Sign() error {
v2.Request.Header["Host"] = []string{host} v2.Request.Header["Host"] = []string{host}
v2.Request.Header["date"] = []string{v2.Time.In(time.UTC).Format(time.RFC1123)} v2.Request.Header["date"] = []string{v2.Time.In(time.UTC).Format(time.RFC1123)}
smap = make(map[string]string)
for k, v := range headers { for k, v := range headers {
k = strings.ToLower(k) k = strings.ToLower(k)
switch k { switch k {
@ -150,16 +153,20 @@ func (v2 *signer) Sign() error {
default: default:
if strings.HasPrefix(k, "x-amz-") { if strings.HasPrefix(k, "x-amz-") {
vall := strings.Join(v, ",") vall := strings.Join(v, ",")
sarray = append(sarray, k+":"+vall) smap[k] = k + ":" + vall
if k == "x-amz-date" { if k == "x-amz-date" {
xamzDate = true xamzDate = true
date = "" date = ""
} }
sharray = append(sharray, k)
} }
} }
} }
if len(sarray) > 0 { if len(sharray) > 0 {
sort.StringSlice(sarray).Sort() sort.StringSlice(sharray).Sort()
for _, h := range sharray {
sarray = append(sarray, smap[h])
}
xamz = strings.Join(sarray, "\n") + "\n" xamz = strings.Join(sarray, "\n") + "\n"
} }