Skip to content

Commit

Permalink
Normalize an empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronf committed Mar 25, 2024
1 parent 261f29c commit fb1602e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func Test_WrapHandler(t *testing.T) {
defer ts.Close()

signer, err := NewHMACSHA256Signer("key", bytes.Repeat([]byte{1}, 64), nil,
Headers("@method", "content-digest"))
Headers("@method", "content-digest", "@request-target"))
assert.NoError(t, err)

verifier, err := NewHMACSHA256Verifier("key", bytes.Repeat([]byte{0}, 64), NewVerifyConfig(), *NewFields())
assert.NoError(t, err)
client := NewDefaultClient(NewClientConfig().SetSignatureName("sig1").SetSigner(signer).SetVerifier(verifier).SetDigestSchemesSend([]string{DigestSha256}))
res, err := client.Post(ts.URL, "text/plain", strings.NewReader("Message body here"))
res, err := client.Post(ts.URL+"?foo", "text/plain", strings.NewReader("Message body here"))
assert.NoError(t, err)
if res != nil {
_, err = io.ReadAll(res.Body)
Expand Down
8 changes: 6 additions & 2 deletions httpparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ func scQuery(url *url.URL) string {
}

func scRequestTarget(url *url.URL) string {
path := url.Path
if path == "" {
path = "/" // Normalize path, issue #8, and see https://www.rfc-editor.org/rfc/rfc9110#section-4.2.3
}
if url.RawQuery == "" {
return url.Path
return path
}
return url.Path + "?" + url.RawQuery
return path + "?" + url.RawQuery
}

func scScheme(url *url.URL) string {
Expand Down

0 comments on commit fb1602e

Please sign in to comment.