Unverified Commit ed9b8863 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

fix: should allow nullable param for res.end (#28694)



## Bug
Fixes #28693

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent 9a6542ba
......@@ -69,12 +69,12 @@ export async function apiResolver(
const writeData = apiRes.write
const endResponse = apiRes.end
apiRes.write = (...args: any[2]) => {
contentLength += Buffer.byteLength(args[0])
contentLength += Buffer.byteLength(args[0] || '')
return writeData.apply(apiRes, args)
}
apiRes.end = (...args: any[2]) => {
if (args.length && typeof args[0] !== 'function') {
contentLength += Buffer.byteLength(args[0])
contentLength += Buffer.byteLength(args[0] || '')
}
if (contentLength >= 4 * 1024 * 1024) {
......
export default (req, res) => {
res.write('')
res.end()
}
......@@ -442,6 +442,11 @@ function runTests(dev = false) {
expect(data).toBe('hi')
})
it('should work with nullable payload', async () => {
const data = await renderViaHTTP(appPort, '/api/nullable-payload')
expect(data).toBe('')
})
it('should warn if response body is larger than 4MB', async () => {
let res = await fetchViaHTTP(appPort, '/api/large-response')
expect(res.ok).toBeTruthy()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment