Skip to content

Commit

Permalink
Modifies REST V2 encoder to not lower-case header names (#472)
Browse files Browse the repository at this point in the history
Modifies the REST v2 encoder to not lower-case values, but use the provided Set/Add headers which will canonicalize the headers.
  • Loading branch information
skmcgrail committed Apr 14, 2020
1 parent c3a274d commit 9a77f74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions aws/protocol/rest/encode_test.go
Expand Up @@ -21,8 +21,8 @@ func TestEncoder(t *testing.T) {
expected := http.Request{
Header: map[string][]string{
"custom-user-header": {"someValue"},
"x-amzn-header-foo": {"someValue"},
"x-amzn-meta-foo": {"someValue"},
"X-Amzn-Header-Foo": {"someValue"},
"X-Amzn-Meta-Foo": {"someValue"},
},
URL: &url.URL{
Path: "/some/someValue/path",
Expand Down
10 changes: 2 additions & 8 deletions aws/protocol/rest/header.go
Expand Up @@ -43,17 +43,11 @@ func newHeaderValue(header http.Header, key string, append bool) HeaderValue {
}

func (h HeaderValue) modifyHeader(value string) {
lk := strings.ToLower(h.key)

val := h.header[lk]

if h.append {
val = append(val, value)
h.header.Add(h.key, value)
} else {
val = append(val[:0], value)
h.header.Set(h.key, value)
}

h.header[lk] = val
}

// String encodes the value v as the header string value
Expand Down
14 changes: 7 additions & 7 deletions aws/protocol/rest/header_test.go
Expand Up @@ -13,7 +13,7 @@ import (

func TestHeaderValue(t *testing.T) {
const keyName = "test-key"
const expectedKeyName = keyName
const expectedKeyName = "Test-Key"

cases := map[string]struct {
header http.Header
Expand Down Expand Up @@ -142,29 +142,29 @@ func TestHeaders(t *testing.T) {
}{
"set": {
headers: http.Header{
"x-amzn-meta-foo": {"bazValue"},
"X-Amzn-Meta-Foo": {"bazValue"},
},
values: map[string]string{
"foo": "fooValue",
" bar ": "barValue",
},
expected: http.Header{
"x-amzn-meta-foo": {"fooValue"},
"x-amzn-meta-bar": {"barValue"},
"X-Amzn-Meta-Foo": {"fooValue"},
"X-Amzn-Meta-Bar": {"barValue"},
},
},
"add": {
headers: http.Header{
"x-amzn-meta-foo": {"bazValue"},
"X-Amzn-Meta-Foo": {"bazValue"},
},
values: map[string]string{
"foo": "fooValue",
" bar ": "barValue",
},
append: true,
expected: http.Header{
"x-amzn-meta-foo": {"bazValue", "fooValue"},
"x-amzn-meta-bar": {"barValue"},
"X-Amzn-Meta-Foo": {"bazValue", "fooValue"},
"X-Amzn-Meta-Bar": {"barValue"},
},
},
}
Expand Down

0 comments on commit 9a77f74

Please sign in to comment.