Skip to content

Commit

Permalink
feat: use undecoded @path and @query according to the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTar committed Jan 12, 2024
1 parent f52b0ee commit 7760e22
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/httpbis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export function deriveComponent(component: string, params: Map<string, string |
throw new Error('Cannot derive @scheme on response');
}
const { pathname } = typeof context.url === 'string' ? new URL(context.url) : context.url;
return [decodeURI(pathname)];
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures#section-2.2.6
// empty path means use `/`
return [pathname || '/'];
}
case '@query': {
if (!isRequest(context)) {
Expand All @@ -102,7 +104,7 @@ export function deriveComponent(component: string, params: Map<string, string |
const { search } = typeof context.url === 'string' ? new URL(context.url) : context.url;
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures#section-2.2.7
// absent query params means use `?`
return [decodeURI(search) || '?'];
return [search || '?'];
}
case '@query-param': {
if (!isRequest(context)) {
Expand Down

0 comments on commit 7760e22

Please sign in to comment.