Skip to content

Commit e11a66d

Browse files
committed
test(helper/proxy): add test for modify header
1 parent 832532c commit e11a66d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/helper/proxy/index.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ describe('Proxy Middleware', () => {
3636
},
3737
})
3838
)
39+
} else if (req.url === 'https://example.com/set-cookie') {
40+
return Promise.resolve(
41+
new Response('ok', {
42+
headers: {
43+
'Set-Cookie': 'test=123',
44+
},
45+
})
46+
)
3947
}
4048
return Promise.resolve(new Response('not found', { status: 404 }))
4149
})
@@ -153,5 +161,23 @@ describe('Proxy Middleware', () => {
153161

154162
expect(res.headers.get('Transfer-Encoding')).toBeNull()
155163
})
164+
165+
it('modify header', async () => {
166+
const app = new Hono()
167+
app.get('/proxy/:path', (c) =>
168+
proxy(`https://example.com/${c.req.param('path')}`, {
169+
headers: {
170+
'Set-Cookie': 'test=123',
171+
},
172+
}).then((res) => {
173+
res.headers.delete('Set-Cookie')
174+
res.headers.set('X-Response-Id', '456')
175+
return res
176+
})
177+
)
178+
const res = await app.request('/proxy/set-cookie')
179+
expect(res.headers.get('Set-Cookie')).toBeNull()
180+
expect(res.headers.get('X-Response-Id')).toBe('456')
181+
})
156182
})
157183
})

0 commit comments

Comments
 (0)