Skip to content
Myr

feat(context): allow URL object on `c.redirect()` (#3609)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* feat(context): allow URL object on `c.redirect()` * Update src/context.ts Co-authored-by: EdamAmex <121654029+EdamAme-x@users.noreply.github.com> ---------

authored by Hyeseong Kim · committed by GitHub · parent 224ec36 · Browse files · 2 files+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: EdamAmex <121654029+EdamAme-x@users.noreply.github.com>

Diff stats

2 files+8 added−2 removed

  • tests:+6 added−0 removed
  • other:+2 added−2 removed

2 files+8 added−2 removed

modified:src/context.test.ts+6 added
87 unmodified lines
88 expect(res.status).toBe(302)89 expect(res.headers.get('Location')).toBe('https://example.com/destination')90 })9192 it('c.redirect() w/ URL', async () => {93 const res = c.redirect(new URL('/destination', 'https://example.com'))94 expect(res.status).toBe(302)95 expect(res.headers.get('Location')).toBe('https://example.com/destination')96 })9798 it('c.header()', async () => {99 c.header('X-Foo', 'Bar')100 const res = c.body('Hi')101 const foo = res.headers.get('X-Foo')
415 unmodified lines
modified:src/context.ts+2 added-2 removed
817 unmodified lines
818 * })819 * ```820 */821 redirect = <T extends RedirectStatusCode = 302>(822 location: string,822 location: string | URL,823 status?: T824 ): Response & TypedResponse<undefined, T, 'redirect'> => {825 this.#headers ??= new Headers()826 this.#headers.set('Location', location)826 this.#headers.set('Location', String(location))827 return this.newResponse(null, status ?? 302) as any828 }829830 /**
16 unmodified lines