// github.com/aws/aws-sdk-go/aws/signer/v4/v4.go func(ctx *signingCtx) buildCanonicalHeaders(r rule, header http.Header) { var headers []string headers = append(headers, "host") for k, v := range header { if !r.IsValid(k) { continue// ignored header } if ctx.SignedHeaderVals == nil { ctx.SignedHeaderVals = make(http.Header) }
lowerCaseKey := strings.ToLower(k) if _, ok := ctx.SignedHeaderVals[lowerCaseKey]; ok { // include additional values ctx.SignedHeaderVals[lowerCaseKey] = append(ctx.SignedHeaderVals[lowerCaseKey], v...) continue }
headers = append(headers, lowerCaseKey) ctx.SignedHeaderVals[lowerCaseKey] = v } sort.Strings(headers)
ctx.signedHeaders = strings.Join(headers, ";") if ctx.isPresign { ctx.Query.Set("X-Amz-SignedHeaders", ctx.signedHeaders) }
headerItems := make([]string, len(headers)) for i, k := range headers { if k == "host" { if ctx.Request.Host != "" { headerItems[i] = "host:" + ctx.Request.Host } else { headerItems[i] = "host:" + ctx.Request.URL.Host } } else { headerValues := make([]string, len(ctx.SignedHeaderVals[k])) for i, v := range ctx.SignedHeaderVals[k] { headerValues[i] = strings.TrimSpace(v) } headerItems[i] = k + ":" + strings.Join(headerValues, ",") } } stripExcessSpaces(headerItems) ctx.canonicalHeaders = strings.Join(headerItems, "\n") }