| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0e864a3 commit 7815d5f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1979,54 +1979,32 @@ Accept: text/plain\r\n | |||
| 1979 | 1979 | \r\n | |
| 1980 | 1980 | ``` | |
| 1981 | 1981 | ||
| 1982 | - Then `request.url` will be: | ||
| 1982 | + To parse the URL into its parts: | ||
| 1983 | 1983 | ||
| 1984 | - <!-- eslint-disable semi --> | ||
| 1985 | 1984 | ```js | |
| 1986 | - '/status?name=ryan' | ||
| 1985 | + new URL(request.url, `http://${request.headers.host}`); | ||
| 1987 | 1986 | ``` | |
| 1988 | 1987 | ||
| 1989 | - To parse the url into its parts `require('url').parse(request.url)` | ||
| 1990 | - can be used: | ||
| 1988 | + When `request.url` is `'/status?name=ryan'` and | ||
| 1989 | + `request.headers.host` is `'localhost:3000'`: | ||
| 1991 | 1990 | ||
| 1992 | 1991 | ```console | |
| 1993 | 1992 | $ node | |
| 1994 | - > require('url').parse('/status?name=ryan') | ||
| 1995 | - Url { | ||
| 1996 | - protocol: null, | ||
| 1997 | - slashes: null, | ||
| 1998 | - auth: null, | ||
| 1999 | - host: null, | ||
| 2000 | - port: null, | ||
| 2001 | - hostname: null, | ||
| 2002 | - hash: null, | ||
| 2003 | - search: '?name=ryan', | ||
| 2004 | - query: 'name=ryan', | ||
| 1993 | + > new URL(request.url, request.headers.host) | ||
| 1994 | + URL { | ||
| 1995 | + href: 'http://localhost:3000/status?name=ryan', | ||
| 1996 | + origin: 'http://localhost:3000', | ||
| 1997 | + protocol: 'http:', | ||
| 1998 | + username: '', | ||
| 1999 | + password: '', | ||
| 2000 | + host: 'localhost:3000', | ||
| 2001 | + hostname: 'localhost', | ||
| 2002 | + port: '3000', | ||
| 2005 | 2003 | pathname: '/status', | |
| 2006 | - path: '/status?name=ryan', | ||
| 2007 | - href: '/status?name=ryan' } | ||
| 2008 | - ``` | ||
| 2009 | - | ||
| 2010 | - To extract the parameters from the query string, the | ||
| 2011 | - `require('querystring').parse` function can be used, or | ||
| 2012 | - `true` can be passed as the second argument to `require('url').parse`: | ||
| 2013 | - | ||
| 2014 | - ```console | ||
| 2015 | - $ node | ||
| 2016 | - > require('url').parse('/status?name=ryan', true) | ||
| 2017 | - Url { | ||
| 2018 | - protocol: null, | ||
| 2019 | - slashes: null, | ||
| 2020 | - auth: null, | ||
| 2021 | - host: null, | ||
| 2022 | - port: null, | ||
| 2023 | - hostname: null, | ||
| 2024 | - hash: null, | ||
| 2025 | 2004 | search: '?name=ryan', | |
| 2026 | - query: { name: 'ryan' }, | ||
| 2027 | - pathname: '/status', | ||
| 2028 | - path: '/status?name=ryan', | ||
| 2029 | - href: '/status?name=ryan' } | ||
| 2005 | + searchParams: URLSearchParams { 'name' => 'ryan' }, | ||
| 2006 | + hash: '' | ||
| 2007 | + } | ||
| 2030 | 2008 | ``` | |
| 2031 | 2009 | ||
| 2032 | 2010 | ## http.METHODS | |
| Back | FazBrowse Home | New Git URL |
0 commit comments