1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23const common = require('../common'); 24const assert = require('assert'); 25const fs = require('fs'); 26const http = require('http'); 27const path = require('path'); 28 29const tmpdir = require('../common/tmpdir'); 30tmpdir.refresh(); 31 32const filename = path.join(tmpdir.path, 'big'); 33let count = 0; 34 35const server = http.createServer((req, res) => { 36 let timeoutId; 37 assert.strictEqual(req.method, 'POST'); 38 req.pause(); 39 40 setTimeout(() => { 41 req.resume(); 42 }, 1000); 43 44 req.on('data', (chunk) => { 45 count += chunk.length; 46 }); 47 48 req.on('end', () => { 49 if (timeoutId) { 50 clearTimeout(timeoutId); 51 } 52 res.writeHead(200, { 'Content-Type': 'text/plain' }); 53 res.end(); 54 }); 55}); 56server.listen(0); 57 58server.on('listening', () => { 59 common.createZeroFilledFile(filename); 60 makeRequest(); 61}); 62 63function makeRequest() { 64 const req = http.request({ 65 port: server.address().port, 66 path: '/', 67 method: 'POST' 68 }); 69 70 const s = fs.ReadStream(filename); 71 s.pipe(req); 72 s.on('close', common.mustSucceed()); 73 74 req.on('response', (res) => { 75 res.resume(); 76 res.on('end', () => { 77 server.close(); 78 }); 79 }); 80} 81 82process.on('exit', () => { 83 assert.strictEqual(count, 1024 * 10240); 84}); 85