| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3ca9e65 commit 1022c0d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,32 +26,34 @@ server.listen(0, function() { | |||
| 26 | 26 | // Create a first request but never finish it | |
| 27 | 27 | const client1 = connect(port); | |
| 28 | 28 | ||
| 29 | - client1.on('close', common.mustCall()); | ||
| 30 | - | ||
| 31 | - client1.on('error', () => {}); | ||
| 29 | + client1.on('connect', common.mustCall(() => { | ||
| 30 | + // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 31 | + const client2 = connect(port); | ||
| 32 | + let response = ''; | ||
| 32 | 33 | ||
| 33 | - client1.write('GET / HTTP/1.1'); | ||
| 34 | + client2.on('data', common.mustCall((chunk) => { | ||
| 35 | + response += chunk.toString('utf-8'); | ||
| 34 | 36 | ||
| 35 | - // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 36 | - const client2 = connect(port); | ||
| 37 | - let response = ''; | ||
| 37 | + if (response.endsWith('0\r\n\r\n')) { | ||
| 38 | + assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 39 | + assert.strictEqual(connections, 2); | ||
| 38 | 40 | ||
| 39 | - client2.on('data', common.mustCall((chunk) => { | ||
| 40 | - response += chunk.toString('utf-8'); | ||
| 41 | + server.closeAllConnections(); | ||
| 42 | + server.close(common.mustCall()); | ||
| 41 | 43 | ||
| 42 | - if (response.endsWith('0\r\n\r\n')) { | ||
| 43 | - assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 44 | - assert.strictEqual(connections, 2); | ||
| 44 | + // This timer should never go off as the server.close should shut everything down | ||
| 45 | + setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref(); | ||
| 46 | + } | ||
| 47 | + })); | ||
| 45 | 48 | ||
| 46 | - server.closeAllConnections(); | ||
| 47 | - server.close(common.mustCall()); | ||
| 49 | + client2.on('close', common.mustCall()); | ||
| 48 | 50 | ||
| 49 | - // This timer should never go off as the server.close should shut everything down | ||
| 50 | - setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref(); | ||
| 51 | - } | ||
| 51 | + client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 52 | 52 | })); | |
| 53 | 53 | ||
| 54 | - client2.on('close', common.mustCall()); | ||
| 54 | + client1.on('close', common.mustCall()); | ||
| 55 | + | ||
| 56 | + client1.on('error', () => {}); | ||
| 55 | 57 | ||
| 56 | - client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 58 | + client1.write('GET / HTTP/1.1'); | ||
| 57 | 59 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,42 +28,44 @@ server.listen(0, function() { | |||
| 28 | 28 | // Create a first request but never finish it | |
| 29 | 29 | const client1 = connect(port); | |
| 30 | 30 | ||
| 31 | - client1.on('close', common.mustCall(() => { | ||
| 32 | - client1Closed = true; | ||
| 33 | - })); | ||
| 31 | + client1.on('connect', common.mustCall(() => { | ||
| 32 | + // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 33 | + const client2 = connect(port); | ||
| 34 | + let response = ''; | ||
| 34 | 35 | ||
| 35 | - client1.on('error', () => {}); | ||
| 36 | + client2.on('data', common.mustCall((chunk) => { | ||
| 37 | + response += chunk.toString('utf-8'); | ||
| 36 | 38 | ||
| 37 | - client1.write('GET / HTTP/1.1'); | ||
| 38 | - | ||
| 39 | - // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 40 | - const client2 = connect(port); | ||
| 41 | - let response = ''; | ||
| 39 | + if (response.endsWith('0\r\n\r\n')) { | ||
| 40 | + assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 41 | + assert.strictEqual(connections, 2); | ||
| 42 | 42 | ||
| 43 | - client2.on('data', common.mustCall((chunk) => { | ||
| 44 | - response += chunk.toString('utf-8'); | ||
| 43 | + server.closeIdleConnections(); | ||
| 44 | + server.close(common.mustCall()); | ||
| 45 | 45 | ||
| 46 | - if (response.endsWith('0\r\n\r\n')) { | ||
| 47 | - assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 48 | - assert.strictEqual(connections, 2); | ||
| 46 | + // Check that only the idle connection got closed | ||
| 47 | + setTimeout(common.mustCall(() => { | ||
| 48 | + assert(!client1Closed); | ||
| 49 | + assert(client2Closed); | ||
| 49 | 50 | ||
| 50 | - server.closeIdleConnections(); | ||
| 51 | - server.close(common.mustCall()); | ||
| 51 | + server.closeAllConnections(); | ||
| 52 | + server.close(common.mustCall()); | ||
| 53 | + }), common.platformTimeout(500)).unref(); | ||
| 54 | + } | ||
| 55 | + })); | ||
| 52 | 56 | ||
| 53 | - // Check that only the idle connection got closed | ||
| 54 | - setTimeout(common.mustCall(() => { | ||
| 55 | - assert(!client1Closed); | ||
| 56 | - assert(client2Closed); | ||
| 57 | + client2.on('close', common.mustCall(() => { | ||
| 58 | + client2Closed = true; | ||
| 59 | + })); | ||
| 57 | 60 | ||
| 58 | - server.closeAllConnections(); | ||
| 59 | - server.close(common.mustCall()); | ||
| 60 | - }), common.platformTimeout(500)).unref(); | ||
| 61 | - } | ||
| 61 | + client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 62 | 62 | })); | |
| 63 | 63 | ||
| 64 | - client2.on('close', common.mustCall(() => { | ||
| 65 | - client2Closed = true; | ||
| 64 | + client1.on('close', common.mustCall(() => { | ||
| 65 | + client1Closed = true; | ||
| 66 | 66 | })); | |
| 67 | 67 | ||
| 68 | - client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 68 | + client1.on('error', () => {}); | ||
| 69 | + | ||
| 70 | + client1.write('GET / HTTP/1.1'); | ||
| 69 | 71 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,32 +37,34 @@ server.listen(0, function() { | |||
| 37 | 37 | // Create a first request but never finish it | |
| 38 | 38 | const client1 = connect({ port, rejectUnauthorized: false }); | |
| 39 | 39 | ||
| 40 | - client1.on('close', common.mustCall()); | ||
| 41 | - | ||
| 42 | - client1.on('error', () => {}); | ||
| 40 | + client1.on('connect', common.mustCall(() => { | ||
| 41 | + // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 42 | + const client2 = connect({ port, rejectUnauthorized: false }); | ||
| 43 | + let response = ''; | ||
| 43 | 44 | ||
| 44 | - client1.write('GET / HTTP/1.1'); | ||
| 45 | + client2.on('data', common.mustCall((chunk) => { | ||
| 46 | + response += chunk.toString('utf-8'); | ||
| 45 | 47 | ||
| 46 | - // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 47 | - const client2 = connect({ port, rejectUnauthorized: false }); | ||
| 48 | - let response = ''; | ||
| 48 | + if (response.endsWith('0\r\n\r\n')) { | ||
| 49 | + assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 50 | + assert.strictEqual(connections, 2); | ||
| 49 | 51 | ||
| 50 | - client2.on('data', common.mustCall((chunk) => { | ||
| 51 | - response += chunk.toString('utf-8'); | ||
| 52 | + server.closeAllConnections(); | ||
| 53 | + server.close(common.mustCall()); | ||
| 52 | 54 | ||
| 53 | - if (response.endsWith('0\r\n\r\n')) { | ||
| 54 | - assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 55 | - assert.strictEqual(connections, 2); | ||
| 55 | + // This timer should never go off as the server.close should shut everything down | ||
| 56 | + setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref(); | ||
| 57 | + } | ||
| 58 | + })); | ||
| 56 | 59 | ||
| 57 | - server.closeAllConnections(); | ||
| 58 | - server.close(common.mustCall()); | ||
| 60 | + client2.on('close', common.mustCall()); | ||
| 59 | 61 | ||
| 60 | - // This timer should never go off as the server.close should shut everything down | ||
| 61 | - setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref(); | ||
| 62 | - } | ||
| 62 | + client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 63 | 63 | })); | |
| 64 | 64 | ||
| 65 | - client2.on('close', common.mustCall()); | ||
| 65 | + client1.on('close', common.mustCall()); | ||
| 66 | + | ||
| 67 | + client1.on('error', () => {}); | ||
| 66 | 68 | ||
| 67 | - client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 69 | + client1.write('GET / HTTP/1.1'); | ||
| 68 | 70 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,42 +39,44 @@ server.listen(0, function() { | |||
| 39 | 39 | // Create a first request but never finish it | |
| 40 | 40 | const client1 = connect({ port, rejectUnauthorized: false }); | |
| 41 | 41 | ||
| 42 | - client1.on('close', common.mustCall(() => { | ||
| 43 | - client1Closed = true; | ||
| 44 | - })); | ||
| 42 | + client1.on('connect', common.mustCall(() => { | ||
| 43 | + // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 44 | + const client2 = connect({ port, rejectUnauthorized: false }); | ||
| 45 | + let response = ''; | ||
| 45 | 46 | ||
| 46 | - client1.on('error', () => {}); | ||
| 47 | + client2.on('data', common.mustCall((chunk) => { | ||
| 48 | + response += chunk.toString('utf-8'); | ||
| 47 | 49 | ||
| 48 | - client1.write('GET / HTTP/1.1'); | ||
| 49 | - | ||
| 50 | - // Create a second request, let it finish but leave the connection opened using HTTP keep-alive | ||
| 51 | - const client2 = connect({ port, rejectUnauthorized: false }); | ||
| 52 | - let response = ''; | ||
| 50 | + if (response.endsWith('0\r\n\r\n')) { | ||
| 51 | + assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 52 | + assert.strictEqual(connections, 2); | ||
| 53 | 53 | ||
| 54 | - client2.on('data', common.mustCall((chunk) => { | ||
| 55 | - response += chunk.toString('utf-8'); | ||
| 54 | + server.closeIdleConnections(); | ||
| 55 | + server.close(common.mustCall()); | ||
| 56 | 56 | ||
| 57 | - if (response.endsWith('0\r\n\r\n')) { | ||
| 58 | - assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive')); | ||
| 59 | - assert.strictEqual(connections, 2); | ||
| 57 | + // Check that only the idle connection got closed | ||
| 58 | + setTimeout(common.mustCall(() => { | ||
| 59 | + assert(!client1Closed); | ||
| 60 | + assert(client2Closed); | ||
| 60 | 61 | ||
| 61 | - server.closeIdleConnections(); | ||
| 62 | - server.close(common.mustCall()); | ||
| 62 | + server.closeAllConnections(); | ||
| 63 | + server.close(common.mustCall()); | ||
| 64 | + }), common.platformTimeout(500)).unref(); | ||
| 65 | + } | ||
| 66 | + })); | ||
| 63 | 67 | ||
| 64 | - // Check that only the idle connection got closed | ||
| 65 | - setTimeout(common.mustCall(() => { | ||
| 66 | - assert(!client1Closed); | ||
| 67 | - assert(client2Closed); | ||
| 68 | + client2.on('close', common.mustCall(() => { | ||
| 69 | + client2Closed = true; | ||
| 70 | + })); | ||
| 68 | 71 | ||
| 69 | - server.closeAllConnections(); | ||
| 70 | - server.close(common.mustCall()); | ||
| 71 | - }), common.platformTimeout(500)).unref(); | ||
| 72 | - } | ||
| 72 | + client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 73 | 73 | })); | |
| 74 | 74 | ||
| 75 | - client2.on('close', common.mustCall(() => { | ||
| 76 | - client2Closed = true; | ||
| 75 | + client1.on('close', common.mustCall(() => { | ||
| 76 | + client1Closed = true; | ||
| 77 | 77 | })); | |
| 78 | 78 | ||
| 79 | - client2.write('GET / HTTP/1.1\r\n\r\n'); | ||
| 79 | + client1.on('error', () => {}); | ||
| 80 | + | ||
| 81 | + client1.write('GET / HTTP/1.1'); | ||
| 80 | 82 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments