mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
doc: improve code snippet alternative of url.parse() using WHATWG URL
PR-URL: https://github.com/nodejs/node/pull/60209 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
da9cd745c8
commit
1cd16e5355
|
|
@ -1853,7 +1853,7 @@ input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
|
|||
function getURL(req) {
|
||||
const proto = req.headers['x-forwarded-proto'] || 'https';
|
||||
const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
|
||||
return new URL(req.url || '/', `${proto}://${host}`);
|
||||
return new URL(`${proto}://${host}${req.url || '/'}`);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1863,7 +1863,7 @@ use the example below:
|
|||
|
||||
```js
|
||||
function getURL(req) {
|
||||
return new URL(req.url || '/', 'https://example.com');
|
||||
return new URL(`https://example.com${req.url || '/'}`);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user