diff --git a/examples/abort-controller/server.js b/examples/abort-controller/server.js index 3ec4ddde..ce45537c 100644 --- a/examples/abort-controller/server.js +++ b/examples/abort-controller/server.js @@ -1,8 +1,13 @@ -import url from 'url'; - export default function (req, res) { - const parsedUrl = url.parse(req.url, true); - const delay = parsedUrl.query.delay || 3000; + let parsedUrl; + try { + parsedUrl = new URL(req.url, 'http://localhost'); + } catch { + res.writeHead(400, { 'Content-Type': 'text/plain' }); + res.end('Invalid URL'); + return; + } + const delay = parsedUrl.searchParams.get('delay') || 3000; setTimeout(() => { res.writeHead(200, { diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8a434376..063be60f 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -668,7 +668,6 @@ export default isHttpAdapterSupported && protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path ); } - let transport; const isHttpsRequest = isHttps.test(options.protocol); options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent; diff --git a/sandbox/server.js b/sandbox/server.js index 401f8750..0246f479 100644 --- a/sandbox/server.js +++ b/sandbox/server.js @@ -1,5 +1,4 @@ import fs from 'fs'; -import url from 'url'; import path from 'path'; import http from 'http'; @@ -76,8 +75,8 @@ function handleApiRequest(req, res) { function requestHandler(req, res) { req.setEncoding('utf8'); - const parsed = url.parse(req.url, true); - let pathname = parsed.pathname; + const parsed = new URL(req.url, 'http://localhost'); + const pathname = parsed.pathname; console.log('[' + new Date() + ']', req.method, pathname); diff --git a/tests/unit/adapters/http.test.js b/tests/unit/adapters/http.test.js index f77ff678..c776c881 100644 --- a/tests/unit/adapters/http.test.js +++ b/tests/unit/adapters/http.test.js @@ -15,7 +15,6 @@ import http from 'http'; import https from 'https'; import net from 'net'; import stream from 'stream'; -import url from 'url'; import zlib from 'zlib'; import fs from 'fs'; import os from 'os'; @@ -492,7 +491,7 @@ describe('supports http with nodejs', () => { return; } - var parsed = url.parse(req.url); + var parsed = new URL(req.url, 'http://localhost'); if (parsed.pathname === '/one') { res.setHeader('Location', '/two'); res.statusCode = 302; @@ -899,7 +898,7 @@ describe('supports http with nodejs', () => { const str = Array(100000).join('ж'); const server = await startHTTPServer( (req, res) => { - const parsed = url.parse(req.url); + const parsed = new URL(req.url, 'http://localhost'); if (parsed.pathname === '/two') { res.setHeader('Content-Type', 'text/html; charset=UTF-8');