From 492c34fa4b594c2b0cb225094bd8779c996c2a3c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 29 Aug 2020 13:30:58 -0700 Subject: [PATCH] doc: recommend URL() over url.parse() in http2 doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/34978 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- doc/api/http2.md | 51 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/doc/api/http2.md b/doc/api/http2.md index a44594ddc583f9..d8de78908fa00c 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -3142,46 +3142,25 @@ Then `request.url` will be: '/status?name=ryan' ``` -To parse the url into its parts, [`url.parse(request.url)`][`url.parse()`]. +To parse the url into its parts, `new URL()` can be used: ```console $ node -> url.parse('/status?name=ryan') -Url { - protocol: null, - slashes: null, - auth: null, - host: null, - port: null, - hostname: null, - hash: null, - search: '?name=ryan', - query: 'name=ryan', +> new URL('/status?name=ryan', 'http://example.com') +URL { + href: 'http://example.com/status?name=ryan', + origin: 'http://example.com', + protocol: 'http:', + username: '', + password: '', + host: 'example.com', + hostname: 'example.com', + port: '', pathname: '/status', - path: '/status?name=ryan', - href: '/status?name=ryan' } -``` - -To obtain the parameters from the query string, use the -[`querystring.parse()`][] function or pass -`true` as the second argument to [`url.parse()`][]. - -```console -$ node -> url.parse('/status?name=ryan', true) -Url { - protocol: null, - slashes: null, - auth: null, - host: null, - port: null, - hostname: null, - hash: null, search: '?name=ryan', - query: { name: 'ryan' }, - pathname: '/status', - path: '/status?name=ryan', - href: '/status?name=ryan' } + searchParams: URLSearchParams { 'name' => 'ryan' }, + hash: '' +} ``` ### Class: `http2.Http2ServerResponse` @@ -3766,7 +3745,6 @@ you need to implement any fall-back behaviour yourself. [`net.Socket.prototype.unref()`]: net.html#net_socket_unref [`net.Socket`]: net.html#net_class_net_socket [`net.connect()`]: net.html#net_net_connect -[`querystring.parse()`]: querystring.html#querystring_querystring_parse_str_sep_eq_options [`request.authority`]: #http2_request_authority [`request.socket`]: #http2_request_socket [`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed @@ -3782,7 +3760,6 @@ you need to implement any fall-back behaviour yourself. [`tls.TLSSocket`]: tls.html#tls_class_tls_tlssocket [`tls.connect()`]: tls.html#tls_tls_connect_options_callback [`tls.createServer()`]: tls.html#tls_tls_createserver_options_secureconnectionlistener -[`url.parse()`]: url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost [`writable.writableFinished`]: stream.html#stream_writable_writablefinished [error code]: #error_codes [Sensitive headers]: #http2-sensitive-headers