diff --git a/src/context.test.ts b/src/context.test.ts index ee02296b..62285260 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('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 af47d958..b8f0e4b4 100644 --- a/src/context.ts +++ b/src/context.ts @@ -819,11 +819,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', String(location)) return this.newResponse(null, status ?? 302) as any }