Skip to content
Myr

fix(proxy): include original request signal in proxy request (#3925)

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

authored by Jonathan Haines · committed by GitHub · parent 0c405b9 · Browse files · 2 files+27 added−0 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+27 added−0 removed

  • tests:+26 added−0 removed
  • other:+1 added−0 removed

2 files+27 added−0 removed

modified:src/helper/proxy/index.test.ts+26 added
5 unmodified lines
6 beforeEach(() => {7 global.fetch = vi.fn().mockImplementation(async (req) => {8 if (req.url === 'https://example.com/ok') {9 return Promise.resolve(new Response('ok'))10 } else if (req.url === 'https://example.com/disconnect') {11 const reader = req.body.getReader()12 let response1314 req.signal.addEventListener('abort', () => {15 response = req.signal.reason16 reader.cancel()17 })1819 await reader.read()2021 return Promise.resolve(new Response(response))22 } else if (req.url === 'https://example.com/compressed') {23 return Promise.resolve(24 new Response('ok', {25 headers: {
185 unmodified lines
211 })212 const req = (global.fetch as ReturnType<typeof vi.fn>).mock.calls[0][0]213 expect(req.headers.get('Authorization')).toBeNull()214 })215216 it('client disconnect', async () => {217 const app = new Hono()218 const controller = new AbortController()219 app.post('/proxy/:path', (c) => proxy(`https://example.com/${c.req.param('path')}`, c.req))220 const resPromise = app.request('/proxy/disconnect', {221 method: 'POST',222 body: 'test',223 signal: controller.signal,224 })225 controller.abort('client disconnect')226 const res = await resPromise227 expect(await res.text()).toBe('client disconnect')228 })229 })230})
modified:src/helper/proxy/index.ts+1 added