Skip to content

Commit 492c34f

Browse files
committed
doc: recommend URL() over url.parse() in http2 doc
PR-URL: #34978 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 51425a8 commit 492c34f

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

doc/api/http2.md

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,46 +3142,25 @@ Then `request.url` will be:
31423142
'/status?name=ryan'
31433143
```
31443144

3145-
To parse the url into its parts, [`url.parse(request.url)`][`url.parse()`].
3145+
To parse the url into its parts, `new URL()` can be used:
31463146

31473147
```console
31483148
$ node
3149-
> url.parse('/status?name=ryan')
3150-
Url {
3151-
protocol: null,
3152-
slashes: null,
3153-
auth: null,
3154-
host: null,
3155-
port: null,
3156-
hostname: null,
3157-
hash: null,
3158-
search: '?name=ryan',
3159-
query: 'name=ryan',
3149+
> new URL('/status?name=ryan', 'http://example.com')
3150+
URL {
3151+
href: 'http://example.com/status?name=ryan',
3152+
origin: 'http://example.com',
3153+
protocol: 'http:',
3154+
username: '',
3155+
password: '',
3156+
host: 'example.com',
3157+
hostname: 'example.com',
3158+
port: '',
31603159
pathname: '/status',
3161-
path: '/status?name=ryan',
3162-
href: '/status?name=ryan' }
3163-
```
3164-
3165-
To obtain the parameters from the query string, use the
3166-
[`querystring.parse()`][] function or pass
3167-
`true` as the second argument to [`url.parse()`][].
3168-
3169-
```console
3170-
$ node
3171-
> url.parse('/status?name=ryan', true)
3172-
Url {
3173-
protocol: null,
3174-
slashes: null,
3175-
auth: null,
3176-
host: null,
3177-
port: null,
3178-
hostname: null,
3179-
hash: null,
31803160
search: '?name=ryan',
3181-
query: { name: 'ryan' },
3182-
pathname: '/status',
3183-
path: '/status?name=ryan',
3184-
href: '/status?name=ryan' }
3161+
searchParams: URLSearchParams { 'name' => 'ryan' },
3162+
hash: ''
3163+
}
31853164
```
31863165

31873166
### Class: `http2.Http2ServerResponse`
@@ -3766,7 +3745,6 @@ you need to implement any fall-back behaviour yourself.
37663745
[`net.Socket.prototype.unref()`]: net.html#net_socket_unref
37673746
[`net.Socket`]: net.html#net_class_net_socket
37683747
[`net.connect()`]: net.html#net_net_connect
3769-
[`querystring.parse()`]: querystring.html#querystring_querystring_parse_str_sep_eq_options
37703748
[`request.authority`]: #http2_request_authority
37713749
[`request.socket`]: #http2_request_socket
37723750
[`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
@@ -3782,7 +3760,6 @@ you need to implement any fall-back behaviour yourself.
37823760
[`tls.TLSSocket`]: tls.html#tls_class_tls_tlssocket
37833761
[`tls.connect()`]: tls.html#tls_tls_connect_options_callback
37843762
[`tls.createServer()`]: tls.html#tls_tls_createserver_options_secureconnectionlistener
3785-
[`url.parse()`]: url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
37863763
[`writable.writableFinished`]: stream.html#stream_writable_writablefinished
37873764
[error code]: #error_codes
37883765
[Sensitive headers]: #http2-sensitive-headers

0 commit comments

Comments
 (0)