2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-01 11:57:14 -06:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
|
|
|
const http = require('http');
|
2011-02-19 16:00:05 -08:00
|
|
|
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2015-06-09 11:40:55 -07:00
|
|
|
|
2023-08-15 22:45:44 +09:00
|
|
|
const filename = tmpdir.resolve('big');
|
2016-12-01 11:57:14 -06:00
|
|
|
let count = 0;
|
2011-02-19 16:00:05 -08:00
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
const server = http.createServer((req, res) => {
|
2018-10-12 11:00:55 -07:00
|
|
|
assert.strictEqual(req.method, 'POST');
|
2011-02-19 16:00:05 -08:00
|
|
|
req.pause();
|
|
|
|
|
2024-08-09 15:12:10 +09:30
|
|
|
const timeoutId = setTimeout(() => {
|
2011-02-19 16:00:05 -08:00
|
|
|
req.resume();
|
|
|
|
}, 1000);
|
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
req.on('data', (chunk) => {
|
2011-02-19 16:00:05 -08:00
|
|
|
count += chunk.length;
|
|
|
|
});
|
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
req.on('end', () => {
|
2011-02-19 16:00:05 -08:00
|
|
|
if (timeoutId) {
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
}
|
2017-07-10 20:55:21 -04:00
|
|
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
2011-02-19 16:00:05 -08:00
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
});
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2011-02-19 16:00:05 -08:00
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
server.on('listening', () => {
|
2025-01-22 14:19:38 -08:00
|
|
|
|
|
|
|
// Create a zero-filled file
|
|
|
|
const fd = fs.openSync(filename, 'w');
|
|
|
|
fs.ftruncateSync(fd, 10 * 1024 * 1024);
|
|
|
|
fs.closeSync(fd);
|
|
|
|
|
2018-10-10 11:24:51 -07:00
|
|
|
makeRequest();
|
2011-02-19 16:00:05 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
function makeRequest() {
|
2016-12-01 11:57:14 -06:00
|
|
|
const req = http.request({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: server.address().port,
|
2011-02-19 16:00:05 -08:00
|
|
|
path: '/',
|
|
|
|
method: 'POST'
|
|
|
|
});
|
|
|
|
|
2016-12-01 11:57:14 -06:00
|
|
|
const s = fs.ReadStream(filename);
|
2011-02-19 16:00:05 -08:00
|
|
|
s.pipe(req);
|
2020-09-06 22:27:07 +02:00
|
|
|
s.on('close', common.mustSucceed());
|
2011-02-19 16:00:05 -08:00
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
req.on('response', (res) => {
|
2012-12-13 09:51:31 -08:00
|
|
|
res.resume();
|
2018-11-21 00:09:06 +05:30
|
|
|
res.on('end', () => {
|
2011-02-19 16:00:05 -08:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-21 00:09:06 +05:30
|
|
|
process.on('exit', () => {
|
2018-10-12 11:00:55 -07:00
|
|
|
assert.strictEqual(count, 1024 * 10240);
|
2011-02-19 16:00:05 -08:00
|
|
|
});
|