message.url


仅对从 http.Server 获取的请求有效。

请求 URL 字符串。它仅包含实际 HTTP 请求中存在的 URL。请看以下请求:

🌐 Request URL string. This contains only the URL that is present in the actual HTTP request. Take the following request:

GET /status?name=ryan HTTP/1.1
Accept: text/plain 

要将网址解析为它的部分:

🌐 To parse the URL into its parts:

new URL(request.url, `http://${request.headers.host}`); 

request.url'/status?name=ryan' 并且 request.headers.host'localhost:3000' 时:

🌐 When request.url is '/status?name=ryan' and request.headers.host is 'localhost:3000':

$ node
> new URL(request.url, `http://${request.headers.host}`)
URL {
  href: 'http://localhost:3000/status?name=ryan',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:3000',
  hostname: 'localhost',
  port: '3000',
  pathname: '/status',
  search: '?name=ryan',
  searchParams: URLSearchParams { 'name' => 'ryan' },
  hash: ''
}