Skip to content

Commit 9a77f74

Browse files
committed
Modifies REST V2 encoder to not lower-case header names (#472)
Modifies the REST v2 encoder to not lower-case values, but use the provided Set/Add headers which will canonicalize the headers.
1 parent c3a274d commit 9a77f74

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

aws/protocol/rest/encode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func TestEncoder(t *testing.T) {
2121
expected := http.Request{
2222
Header: map[string][]string{
2323
"custom-user-header": {"someValue"},
24-
"x-amzn-header-foo": {"someValue"},
25-
"x-amzn-meta-foo": {"someValue"},
24+
"X-Amzn-Header-Foo": {"someValue"},
25+
"X-Amzn-Meta-Foo": {"someValue"},
2626
},
2727
URL: &url.URL{
2828
Path: "/some/someValue/path",

aws/protocol/rest/header.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@ func newHeaderValue(header http.Header, key string, append bool) HeaderValue {
4343
}
4444

4545
func (h HeaderValue) modifyHeader(value string) {
46-
lk := strings.ToLower(h.key)
47-
48-
val := h.header[lk]
49-
5046
if h.append {
51-
val = append(val, value)
47+
h.header.Add(h.key, value)
5248
} else {
53-
val = append(val[:0], value)
49+
h.header.Set(h.key, value)
5450
}
55-
56-
h.header[lk] = val
5751
}
5852

5953
// String encodes the value v as the header string value

aws/protocol/rest/header_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

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

1818
cases := map[string]struct {
1919
header http.Header
@@ -142,29 +142,29 @@ func TestHeaders(t *testing.T) {
142142
}{
143143
"set": {
144144
headers: http.Header{
145-
"x-amzn-meta-foo": {"bazValue"},
145+
"X-Amzn-Meta-Foo": {"bazValue"},
146146
},
147147
values: map[string]string{
148148
"foo": "fooValue",
149149
" bar ": "barValue",
150150
},
151151
expected: http.Header{
152-
"x-amzn-meta-foo": {"fooValue"},
153-
"x-amzn-meta-bar": {"barValue"},
152+
"X-Amzn-Meta-Foo": {"fooValue"},
153+
"X-Amzn-Meta-Bar": {"barValue"},
154154
},
155155
},
156156
"add": {
157157
headers: http.Header{
158-
"x-amzn-meta-foo": {"bazValue"},
158+
"X-Amzn-Meta-Foo": {"bazValue"},
159159
},
160160
values: map[string]string{
161161
"foo": "fooValue",
162162
" bar ": "barValue",
163163
},
164164
append: true,
165165
expected: http.Header{
166-
"x-amzn-meta-foo": {"bazValue", "fooValue"},
167-
"x-amzn-meta-bar": {"barValue"},
166+
"X-Amzn-Meta-Foo": {"bazValue", "fooValue"},
167+
"X-Amzn-Meta-Bar": {"barValue"},
168168
},
169169
},
170170
}

0 commit comments

Comments
 (0)