Fixed url.parse deprecation
This commit is contained in:
+24
-1
@@ -129,11 +129,34 @@ class CRequest
|
|||||||
get isPost() { return this.raw.method == 'POST'; }
|
get isPost() { return this.raw.method == 'POST'; }
|
||||||
get remoteAddr() { return this.raw.socket.remoteAddress; }
|
get remoteAddr() { return this.raw.socket.remoteAddress; }
|
||||||
|
|
||||||
|
compat_parse_url( url, base = "http://example.invalid" )
|
||||||
|
{
|
||||||
|
var u = new URL( url, base );
|
||||||
|
var isRelative = !/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
|
||||||
|
|
||||||
|
return {
|
||||||
|
protocol: isRelative ? null : u.protocol,
|
||||||
|
slashes: isRelative ? null : true,
|
||||||
|
auth: u.username || u.password
|
||||||
|
? `${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`
|
||||||
|
: null,
|
||||||
|
host: isRelative ? null : u.host,
|
||||||
|
port: isRelative ? null : (u.port || null),
|
||||||
|
hostname: isRelative ? null : u.hostname,
|
||||||
|
hash: u.hash || null,
|
||||||
|
search: u.search || null,
|
||||||
|
query: u.search ? u.search.slice(1) : null,
|
||||||
|
pathname: u.pathname,
|
||||||
|
path: u.pathname + u.search,
|
||||||
|
href: isRelative ? u.pathname + u.search + u.hash : u.href,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
constructor( req, Http )
|
constructor( req, Http )
|
||||||
{
|
{
|
||||||
this.raw = req;
|
this.raw = req;
|
||||||
this.headers = req.headers;
|
this.headers = req.headers;
|
||||||
this.uri = require('url').parse( req.url );
|
this.uri = this.compat_parse_url( req.url );
|
||||||
this.cookie = new Cookie( req.headers.cookie, Http );
|
this.cookie = new Cookie( req.headers.cookie, Http );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user