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