Skip to content
Myr

fix(method-override): set duplex when forwarding a stream body in query mode (#5110)

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

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

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

2 files+26 added−2 removed

modified:src/middleware/method-override/index.test.ts+22 added
183 unmodified lines
184 queryValue: null,185 })186 })187188 it('Should override POST to DELETE when the request has a body', async () => {189 const app = new Hono()190 app.use('/posts/*', methodOverride({ app, query: '_method' }))191 app.on(['post', 'delete'], '/posts', async (c) => {192 return c.json({193 method: c.req.method,194 body: await c.req.text(),195 queryValue: c.req.query('_method') ?? null,196 })197 })198 const res = await app.request('/posts?_method=delete', {199 method: 'POST',200 body: new URLSearchParams({ message: 'Hello' }),201 })202 expect(res.status).toBe(200)203 expect(await res.json()).toEqual({204 method: 'DELETE',205 body: 'message=Hello',206 queryValue: null,207 })208 })209210 it('Should not override GET request', async () => {211 const res = await app.request('/posts?_method=delete', {212 method: 'GET',213 })
8 unmodified lines
modified:src/middleware/method-override/index.ts+4 added-2 removed