Skip to content
Myr

feat(proxy): add `customFetch` option to allow custom fetch function (#4360)

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

* feat(proxy): add `fetch` option to allow custom fetch function * update the API * make it optional

authored by Yusuke Wada · committed by GitHub · parent d1c072a · Browse files · 2 files+23 added−2 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+23 added−2 removed

  • tests:+20 added−0 removed
  • other:+3 added−2 removed

2 files+23 added−2 removed

modified:src/helper/proxy/index.test.ts+20 added
253 unmodified lines
254255 expect(res.status).toBe(200)256 expect(await res.text()).toBe('ok')257 })258259 it('Should call the custom fetch method when specified', async () => {260 const customFetch = vi.fn().mockImplementation(async (req: Request) => {261 const text = await req.text()262 return new Response('custom fetch response. message:' + text)263 })264 const app = new Hono()265 app.post('/', (c) => {266 return proxy(`https://example.com/`, {267 customFetch,268 ...c.req,269 })270 })271 const res = await app.request('/', {272 method: 'POST',273 body: 'hi',274 })275 expect(res.status).toBe(200)276 expect(await res.text()).toBe('custom fetch response. message:hi')277 })278 })279})
modified:src/helper/proxy/index.ts+3 added-2 removed