-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NewAPIGatewayProxyResponse handles Headers with multiple values, and …
…ensuring canonicalized header keys
- Loading branch information
1 parent
7055c9e
commit 7c052c7
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package shim | ||
|
||
import ( | ||
"net/http" | ||
"sort" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestFormatHeadersCanonicalizesKeyNames(t *testing.T) { | ||
h := make(http.Header) | ||
encoding := "gzip" | ||
h["accept-encoding"] = []string{"gzip"} | ||
f := formatHeaders(h) | ||
|
||
v, ok := f["Accept-Encoding"] | ||
if !ok { | ||
t.Error("expected to get key Accept-Encoding to have a value") | ||
} | ||
|
||
if v != encoding { | ||
t.Errorf("expected encoding to be %v but was %v", encoding, v) | ||
} | ||
} | ||
|
||
func TestFormatHeadersHandlesMultipleValusForAKey(t *testing.T) { | ||
h := make(http.Header) | ||
gzip := "gzip" | ||
deflate := "deflate" | ||
encodings := []string{gzip, deflate} | ||
h["Accept-Encoding"] = encodings | ||
f := formatHeaders(h) | ||
|
||
v, ok := f["Accept-Encoding"] | ||
if !ok { | ||
t.Fatal("expected value for Accept-Encoding to be present") | ||
} | ||
|
||
encodingVals := strings.Split(v, multipleValueSeperator) | ||
if len(encodingVals) != len(encodings) { | ||
t.Fatalf("expected number of encoded values to be %v but was %v\n", len(encodings), len(encodingVals)) | ||
} | ||
|
||
sort.Strings(encodings) | ||
sort.Strings(encodingVals) | ||
|
||
for i, encoding := range encodings { | ||
if encodingVals[i] != encoding { | ||
t.Errorf("expected encoding at %v to be %v but was %v\n", i, encoding, encodingVals[i]) | ||
} | ||
} | ||
} |