mirror of
https://github.com/axios/axios.git
synced 2026-04-11 02:11:50 +08:00
* Fixes #10610 Deprecation Warning : url.parse() is deprecated in Node.js v22 (via follow-redirects) * Fixes #10610 Deprecation Warning : fixed again * Apply suggestion from @cubic-dev-ai[bot] Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: tona jose <tona00jose@gmail.com> Co-authored-by: Jay <jasonsaayman@gmail.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
parent
a04dd96dbb
commit
947f7091d8
@ -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, {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user