Skip to content
Myr

fix(proxy): accept a Request object as proxyInit (#4067)

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

authored by Taku Amano · committed by GitHub · parent 02377ef · Browse files · 2 files+24 added−1 removed
This commit

State

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

Diff stats

2 files+24 added−1 removed

  • tests:+22 added−0 removed
  • other:+2 added−1 removed

2 files+24 added−1 removed

modified:src/helper/proxy/index.test.ts+22 added
231 unmodified lines
232 app.get('/proxy/:path', (c) => proxy(`https://example.com/${c.req.param('path')}`))233 const res = await app.request('/proxy/404')234 expect(res.status).toBe(404)235 })236237 it('pass a Request object to proxyInit', async () => {238 const app = new Hono()239 app.get('/proxy/:path', (c) => {240 const req = new Request(c.req.raw, {241 headers: {242 'X-Request-Id': '123',243 'Accept-Encoding': 'gzip',244 },245 })246 return proxy(`https://example.com/${c.req.param('path')}`, req)247 })248 const res = await app.request('/proxy/compressed')249 const req = (global.fetch as ReturnType<typeof vi.fn>).mock.calls[0][0]250251 expect(req.url).toBe('https://example.com/compressed')252 expect(req.headers.get('X-Request-Id')).toBe('123')253 expect(req.headers.get('Accept-Encoding')).toBeNull()254255 expect(res.status).toBe(200)256 expect(await res.text()).toBe('ok')257 })258 })259})
modified:src/helper/proxy/index.ts+2 added-1 removed