|
| 1 | +'use strict'; |
| 2 | +constcommon=require('../common'); |
| 3 | +consthttp=require('http'); |
| 4 | +constassert=require('assert'); |
| 5 | +constCountdown=require('../common/countdown'); |
| 6 | + |
| 7 | +// The HEAD:204, GET:200 is the most pathological test case. |
| 8 | +// GETs following a 204 response with a content-encoding header failed. |
| 9 | +// Responses without bodies and without content-length or encoding caused |
| 10 | +// the socket to be closed. |
| 11 | +constcodes=[204,200,200,304,200]; |
| 12 | +constmethods=['HEAD','HEAD','GET','HEAD','GET']; |
| 13 | + |
| 14 | +constsockets=[]; |
| 15 | +constagent=newhttp.Agent(); |
| 16 | +agent.maxSockets=1; |
| 17 | + |
| 18 | +constcountdown=newCountdown(codes.length,()=>server.close()); |
| 19 | + |
| 20 | +constserver=http.createServer(common.mustCall((req,res)=>{ |
| 21 | +constcode=codes.shift(); |
| 22 | +assert.strictEqual(typeofcode,'number'); |
| 23 | +assert.ok(code>0); |
| 24 | +res.writeHead(code,{}); |
| 25 | +res.end(); |
| 26 | +},codes.length)); |
| 27 | + |
| 28 | +functionnextRequest(){ |
| 29 | +constrequest=http.request({ |
| 30 | +port: server.address().port, |
| 31 | +path: '/', |
| 32 | +agent: agent, |
| 33 | +method: methods.shift() |
| 34 | +},common.mustCall((response)=>{ |
| 35 | +response.on('end',common.mustCall(()=>{ |
| 36 | +if(countdown.dec()){ |
| 37 | +nextRequest(); |
| 38 | +} |
| 39 | +assert.strictEqual(sockets.length,1); |
| 40 | +})); |
| 41 | +response.resume(); |
| 42 | +})); |
| 43 | +request.on('socket',common.mustCall((socket)=>{ |
| 44 | +if(!sockets.includes(socket)){ |
| 45 | +sockets.push(socket); |
| 46 | +} |
| 47 | +})); |
| 48 | +request.end(); |
| 49 | +} |
| 50 | + |
| 51 | +server.listen(0,common.mustCall(nextRequest)); |
0 commit comments