| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c39d5fc commit 214da63
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,34 +15,19 @@ await once(server, 'listening'); | |||
| 15 | 15 | const serverHost = `localhost:${server.address().port}`; | |
| 16 | 16 | const requestUrl = `http://${serverHost}/test`; | |
| 17 | 17 | ||
| 18 | - let maxRetries = 10; | ||
| 19 | 18 | let foundRefused = false; | |
| 20 | - while (maxRetries-- > 0) { | ||
| 21 | - // Make it fail on connection refused by connecting to a port of a closed server. | ||
| 22 | - // If it succeeds, get a different port and retry. | ||
| 23 | - const proxy = http.createServer((req, res) => { | ||
| 24 | - res.destroy(); | ||
| 25 | - }); | ||
| 26 | - proxy.listen(0); | ||
| 27 | - await once(proxy, 'listening'); | ||
| 28 | - const port = proxy.address().port; | ||
| 29 | - proxy.close(); | ||
| 30 | - await once(proxy, 'close'); | ||
| 19 | + const port = 10; | ||
| 20 | + console.log(`Trying proxy at port ${port}`); | ||
| 21 | + const { stderr } = await runProxiedRequest({ | ||
| 22 | + NODE_USE_ENV_PROXY: 1, | ||
| 23 | + REQUEST_URL: requestUrl, | ||
| 24 | + HTTP_PROXY: `http://127.0.0.1:${port}`, | ||
| 25 | + NO_PROXY: '', | ||
| 26 | + no_proxy: '', | ||
| 27 | + REQUEST_TIMEOUT: 5000, | ||
| 28 | + }); | ||
| 31 | 29 | ||
| 32 | - console.log(`Trying proxy at port ${port}`); | ||
| 33 | - const { stderr } = await runProxiedRequest({ | ||
| 34 | - NODE_USE_ENV_PROXY: 1, | ||
| 35 | - REQUEST_URL: requestUrl, | ||
| 36 | - HTTP_PROXY: `http://localhost:${port}`, | ||
| 37 | - REQUEST_TIMEOUT: 5000, | ||
| 38 | - }); | ||
| 39 | - | ||
| 40 | - foundRefused = /Error.*connect ECONNREFUSED/.test(stderr); | ||
| 41 | - if (foundRefused) { | ||
| 42 | - // The proxy client should get a connection refused error. | ||
| 43 | - break; | ||
| 44 | - } | ||
| 45 | - } | ||
| 30 | + foundRefused = /Error.*connect ECONNREFUSED/.test(stderr); | ||
| 46 | 31 | ||
| 47 | 32 | server.close(); | |
| 48 | 33 | assert(foundRefused, 'Expected ECONNREFUSED error from proxy request'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ import fixtures from '../common/fixtures.js'; | |||
| 5 | 5 | import assert from 'node:assert'; | |
| 6 | 6 | import { once } from 'events'; | |
| 7 | 7 | import { runProxiedRequest } from '../common/proxy-server.js'; | |
| 8 | - import http from 'node:http'; | ||
| 9 | 8 | ||
| 10 | 9 | if (!common.hasCrypto) | |
| 11 | 10 | common.skip('missing crypto'); | |
@@ -25,35 +24,20 @@ await once(server, 'listening'); | |||
| 25 | 24 | const serverHost = `localhost:${server.address().port}`; | |
| 26 | 25 | const requestUrl = `https://${serverHost}/test`; | |
| 27 | 26 | ||
| 28 | - let maxRetries = 10; | ||
| 29 | 27 | let foundRefused = false; | |
| 30 | - while (maxRetries-- > 0) { | ||
| 31 | - // Make it fail on connection refused by connecting to a port of a closed server. | ||
| 32 | - // If it succeeds, get a different port and retry. | ||
| 33 | - const proxy = http.createServer((req, res) => { | ||
| 34 | - res.destroy(); | ||
| 35 | - }); | ||
| 36 | - proxy.listen(0); | ||
| 37 | - await once(proxy, 'listening'); | ||
| 38 | - const port = proxy.address().port; | ||
| 39 | - proxy.close(); | ||
| 40 | - await once(proxy, 'close'); | ||
| 41 | - | ||
| 42 | - console.log(`Trying proxy at port ${port}`); | ||
| 43 | - const { stderr } = await runProxiedRequest({ | ||
| 44 | - NODE_USE_ENV_PROXY: 1, | ||
| 45 | - REQUEST_URL: requestUrl, | ||
| 46 | - HTTPS_PROXY: `http://localhost:${port}`, | ||
| 47 | - NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'fake-startcom-root-cert.pem'), | ||
| 48 | - REQUEST_TIMEOUT: 5000, | ||
| 49 | - }); | ||
| 50 | - | ||
| 51 | - foundRefused = /Error.*connect ECONNREFUSED/.test(stderr); | ||
| 52 | - if (foundRefused) { | ||
| 53 | - // The proxy client should get a connection refused error. | ||
| 54 | - break; | ||
| 55 | - } | ||
| 56 | - } | ||
| 28 | + const port = 10; | ||
| 29 | + console.log(`Trying proxy at port ${port}`); | ||
| 30 | + const { stderr } = await runProxiedRequest({ | ||
| 31 | + NODE_USE_ENV_PROXY: 1, | ||
| 32 | + REQUEST_URL: requestUrl, | ||
| 33 | + HTTPS_PROXY: `http://127.0.0.1:${port}`, | ||
| 34 | + NO_PROXY: '', | ||
| 35 | + no_proxy: '', | ||
| 36 | + NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'fake-startcom-root-cert.pem'), | ||
| 37 | + REQUEST_TIMEOUT: 5000, | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + foundRefused = /Error.*connect ECONNREFUSED/.test(stderr); | ||
| 57 | 41 | ||
| 58 | 42 | server.close(); | |
| 59 | 43 | assert(foundRefused, 'Expected ECONNREFUSED error from proxy request'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments