mirror of
https://github.com/axios/axios.git
synced 2026-04-11 14:21:59 +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) {
|
export default function (req, res) {
|
||||||
const parsedUrl = url.parse(req.url, true);
|
let parsedUrl;
|
||||||
const delay = parsedUrl.query.delay || 3000;
|
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(() => {
|
setTimeout(() => {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
|
|||||||
@ -668,7 +668,6 @@ export default isHttpAdapterSupported &&
|
|||||||
protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path
|
protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let transport;
|
let transport;
|
||||||
const isHttpsRequest = isHttps.test(options.protocol);
|
const isHttpsRequest = isHttps.test(options.protocol);
|
||||||
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import url from 'url';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
|
|
||||||
@ -76,8 +75,8 @@ function handleApiRequest(req, res) {
|
|||||||
function requestHandler(req, res) {
|
function requestHandler(req, res) {
|
||||||
req.setEncoding('utf8');
|
req.setEncoding('utf8');
|
||||||
|
|
||||||
const parsed = url.parse(req.url, true);
|
const parsed = new URL(req.url, 'http://localhost');
|
||||||
let pathname = parsed.pathname;
|
const pathname = parsed.pathname;
|
||||||
|
|
||||||
console.log('[' + new Date() + ']', req.method, pathname);
|
console.log('[' + new Date() + ']', req.method, pathname);
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import http from 'http';
|
|||||||
import https from 'https';
|
import https from 'https';
|
||||||
import net from 'net';
|
import net from 'net';
|
||||||
import stream from 'stream';
|
import stream from 'stream';
|
||||||
import url from 'url';
|
|
||||||
import zlib from 'zlib';
|
import zlib from 'zlib';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
@ -492,7 +491,7 @@ describe('supports http with nodejs', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsed = url.parse(req.url);
|
var parsed = new URL(req.url, 'http://localhost');
|
||||||
if (parsed.pathname === '/one') {
|
if (parsed.pathname === '/one') {
|
||||||
res.setHeader('Location', '/two');
|
res.setHeader('Location', '/two');
|
||||||
res.statusCode = 302;
|
res.statusCode = 302;
|
||||||
@ -899,7 +898,7 @@ describe('supports http with nodejs', () => {
|
|||||||
const str = Array(100000).join('ж');
|
const str = Array(100000).join('ж');
|
||||||
const server = await startHTTPServer(
|
const server = await startHTTPServer(
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
const parsed = url.parse(req.url);
|
const parsed = new URL(req.url, 'http://localhost');
|
||||||
|
|
||||||
if (parsed.pathname === '/two') {
|
if (parsed.pathname === '/two') {
|
||||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user