| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ee0a98b commit fb8470a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,9 @@ const assert = require('assert'); | |||
| 25 | 25 | ||
| 26 | 26 | const http = require('http'); | |
| 27 | 27 | ||
| 28 | - const server = http.createServer(function(request, response) { | ||
| 28 | + const server = http.createServer(common.mustCall(function(request, response) { | ||
| 29 | + const socket = response.socket; | ||
| 30 | + | ||
| 29 | 31 | // Removed headers should stay removed, even if node automatically adds them | |
| 30 | 32 | // to the output: | |
| 31 | 33 | response.removeHeader('connection'); | |
@@ -36,32 +38,29 @@ const server = http.createServer(function(request, response) { | |||
| 36 | 38 | response.removeHeader('date'); | |
| 37 | 39 | response.setHeader('date', 'coffee o clock'); | |
| 38 | 40 | ||
| 39 | - response.end('beep boop\n'); | ||
| 40 | - }); | ||
| 41 | - | ||
| 42 | - let response = ''; | ||
| 41 | + response.on('finish', common.mustCall(function() { | ||
| 42 | + // The socket should be closed immediately, with no keep-alive, because | ||
| 43 | + // no content-length or transfer-encoding are used. | ||
| 44 | + assert.strictEqual(socket.writableEnded, true); | ||
| 45 | + })); | ||
| 43 | 46 | ||
| 44 | - process.on('exit', function() { | ||
| 45 | - assert.strictEqual(response, 'beep boop\n'); | ||
| 46 | - console.log('ok'); | ||
| 47 | - }); | ||
| 47 | + response.end('beep boop\n'); | ||
| 48 | + })); | ||
| 48 | 49 | ||
| 49 | 50 | server.listen(0, function() { | |
| 50 | 51 | http.get({ port: this.address().port }, function(res) { | |
| 51 | 52 | assert.strictEqual(res.statusCode, 200); | |
| 52 | 53 | assert.deepStrictEqual(res.headers, { date: 'coffee o clock' }); | |
| 53 | 54 | ||
| 55 | + let response = ''; | ||
| 54 | 56 | res.setEncoding('ascii'); | |
| 55 | 57 | res.on('data', function(chunk) { | |
| 56 | 58 | response += chunk; | |
| 57 | - if (response === 'beep boop\n') { | ||
| 58 | - setTimeout(function() { | ||
| 59 | - // The socket should be closed immediately, with no keep-alive, because | ||
| 60 | - // no content-length or transfer-encoding are used: | ||
| 61 | - assert.strictEqual(res.socket.closed, true); | ||
| 62 | - server.close(); | ||
| 63 | - }, common.platformTimeout(15)); | ||
| 64 | - } | ||
| 59 | + }); | ||
| 60 | + | ||
| 61 | + res.on('end', function() { | ||
| 62 | + assert.strictEqual(response, 'beep boop\n'); | ||
| 63 | + server.close(); | ||
| 65 | 64 | }); | |
| 66 | 65 | }); | |
| 67 | 66 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments