diff --git a/src/context.test.ts b/src/context.test.ts index ee02296bdc..1db4ddcb73 100644 --- a/src/context.test.ts +++ b/src/context.test.ts @@ -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')) + }) + it('c.header()', async () => { c.header('X-Foo', 'Bar') const res = c.body('Hi') diff --git a/src/context.ts b/src/context.ts index a23942e026..3661e0122c 100644 --- a/src/context.ts +++ b/src/context.ts @@ -820,11 +820,11 @@ export class Context< * ``` */ redirect = ( - location: string, + location: string | URL, status?: T ): Response & TypedResponse => { this.#headers ??= new Headers() - this.#headers.set('Location', location) + this.#headers.set('Location', location.toString()) return this.newResponse(null, status ?? 302) as any }