Skip to content

Commit

Permalink
Merge pull request #1 from greut/master
Browse files Browse the repository at this point in the history
ETag are expecting to be enclosed in quotes.
  • Loading branch information
amalfra authored Aug 16, 2017
2 parents 2db96d7 + 6a3143f commit 68225ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion etag.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func getHash(str string) string {
// Generate an Etag for given sring. Allows specifying whether to generate weak
// Etag or not as second parameter
func Generate(str string, weak bool) string {
tag := fmt.Sprintf("%d-%s", len(str), getHash(str))
tag := fmt.Sprintf("\"%d-%s\"", len(str), getHash(str))
if weak {
tag = "W/" + tag
}
Expand Down
4 changes: 2 additions & 2 deletions etag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNotWeekEtag(t *testing.T) {
<p>test page html</p>
</body>
</html>`
expectedOut := fmt.Sprintf("%d-%s", len(inputStr), getHash(inputStr))
expectedOut := fmt.Sprintf("\"%d-%s\"", len(inputStr), getHash(inputStr))
generatedOut := Generate(inputStr, false)
if generatedOut != expectedOut {
t.Fatalf("Incorrect Etag generated")
Expand All @@ -30,7 +30,7 @@ func TestWeekEtag(t *testing.T) {
<p>test page html</p>
</body>
</html>`
expectedOut := fmt.Sprintf("W/%d-%s", len(inputStr), getHash(inputStr))
expectedOut := fmt.Sprintf("W/\"%d-%s\"", len(inputStr), getHash(inputStr))
generatedOut := Generate(inputStr, true)
if generatedOut != expectedOut {
t.Fatalf("Incorrect Etag generated")
Expand Down

0 comments on commit 68225ad

Please sign in to comment.