1'use strict'; 2const common = require('../common'); 3const http = require('http'); 4 5let onPause = null; 6 7const server = http.createServer((req, res) => { 8 if (req.method === 'GET') 9 return res.end(); 10 11 res.writeHead(200); 12 res.flushHeaders(); 13 14 req.on('close', common.mustCall(() => { 15 req.on('end', common.mustNotCall()); 16 })); 17 18 req.connection.on('pause', () => { 19 res.end(); 20 onPause(); 21 }); 22}).listen(0, common.mustCall(() => { 23 const agent = new http.Agent({ 24 maxSockets: 1, 25 keepAlive: true 26 }); 27 28 const port = server.address().port; 29 30 const post = http.request({ 31 agent, 32 method: 'POST', 33 port, 34 }, common.mustCall((res) => { 35 res.resume(); 36 37 post.write(Buffer.alloc(16 * 1024).fill('X')); 38 onPause = () => { 39 post.end('something'); 40 }; 41 })); 42 43 // What happens here is that the server `end`s the response before we send 44 // `something`, and the client thought that this is a green light for sending 45 // next GET request 46 post.write('initial'); 47 48 http.request({ 49 agent, 50 method: 'GET', 51 port, 52 }, common.mustCall((res) => { 53 server.close(); 54 res.connection.end(); 55 })).end(); 56})); 57