Skip to content

Commit

Permalink
allow URL object on c.redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 1, 2024
1 parent ae99d86 commit e349a00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ describe('Context', () => {
expect(res.headers.get('Location')).toBe('https://example.com/destination')
})

it('c.redirect() w/ URL', async () => {
const res = c.redirect(new URL('/destination', 'https://example.com'))
expect(res.status).toBe(302)
expect(res.headers.get('Location')).toBe(new URL('https://example.com/destination'))

Check failure on line 95 in src/context.test.ts

View workflow job for this annotation

GitHub Actions / Main

src/context.test.ts > Context > c.redirect() w/ URL

AssertionError: expected 'https://example.com/destination' to be URL{} // Object.is equality - Expected: URL {} + Received: "https://example.com/destination" ❯ src/context.test.ts:95:41
})

it('c.header()', async () => {
c.header('X-Foo', 'Bar')
const res = c.body('Hi')
Expand Down
4 changes: 2 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ export class Context<
* ```
*/
redirect = <T extends RedirectStatusCode = 302>(
location: string,
location: string | URL,
status?: T
): Response & TypedResponse<undefined, T, 'redirect'> => {
this.#headers ??= new Headers()
this.#headers.set('Location', location)
this.#headers.set('Location', location.toString())
return this.newResponse(null, status ?? 302) as any
}

Expand Down

0 comments on commit e349a00

Please sign in to comment.