-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't timeout while waiting for client to send request (#1604)
* fix: don't timeout while waiting for client to send request When e.g. uploading a large file from the client one would always get a headers timeout even though everything was working and the file was being in progress of sending. * fixuP
- Loading branch information
Showing
6 changed files
with
69 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { Client } = require('..') | ||
const { createServer } = require('http') | ||
const { Readable } = require('stream') | ||
|
||
test('request timeout with slow readable body', (t) => { | ||
t.plan(1) | ||
|
||
const server = createServer(async (req, res) => { | ||
let str = '' | ||
for await (const x of req) { | ||
str += x | ||
} | ||
res.end(str) | ||
}) | ||
t.teardown(server.close.bind(server)) | ||
|
||
server.listen(0, () => { | ||
const client = new Client(`http://localhost:${server.address().port}`, { headersTimeout: 50 }) | ||
t.teardown(client.close.bind(client)) | ||
|
||
const body = new Readable({ | ||
read () { | ||
if (this._reading) { | ||
return | ||
} | ||
this._reading = true | ||
|
||
this.push('asd') | ||
setTimeout(() => { | ||
this.push('asd') | ||
this.push(null) | ||
}, 2e3) | ||
} | ||
}) | ||
client.request({ | ||
path: '/', | ||
method: 'POST', | ||
headersTimeout: 1e3, | ||
body | ||
}, async (err, response) => { | ||
t.error(err) | ||
await response.body.dump() | ||
}) | ||
}) | ||
}) |