相对请求时HOSTheader取自哪里?

Where is the HOST header taken from when relative requests are made?

根据 SPEC :

The most common form of Request-URI is that used to identify a resource on an origin server or gateway. In this case the absolute path of the URI MUST be transmitted as the Request-URI, and the network location of the URI (authority) MUST be transmitted in a Host header field.
For example, a client wishing to retrieve the resource above directly from the origin server would create a TCP connection to port 80 of the host "www.w3.org" and send the lines:

   GET /pub/WWW/TheProject.html HTTP/1.1
   Host: www.w3.org

因此,当用户发出此请求时,它会得到响应。

好的,现在这个循环 over(!) - 用户点击 <a href="/help">Help</a> link.

Example (look in the iframe's view source) :

好的。那么问题是什么?

问题

如果用户点击 hyperlink,浏览器如何知道要转到 host 值?据我所知,它不是来自地址栏 url .

我知道 document.location 包含所有信息,但仍然 - 我认为 JS 不涉及这里。

知道上一个周期(请求)已经结束(第一个请求)- host header 值是从哪里获取的?

SPEC 参考将不胜感激。

编辑:

I've been investigating it 一点 Fiddler:

因此 html :

<body>
  <a href="/GetSomething"> Click me</a>
</body>

Fiddler 显示此结果:

GET http://null.jsbin.com/GetSomething HTTP/1.1
Host: null.jsbin.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36
DNT: 1
Referer: http://null.jsbin.com/runner
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,he;q=0.6
Cookie: _ga=GA1.2.474312101.1437654587; _gat=1; jsbin=s%3A...

URL 是完整的 URL (显然):

http://null.jsbin.com/GetSomething

这可能是一个非常简单的问题,但仍然 - 它从哪里获取 BASE url? (Javascript ( document.location?) ? 地址栏 url ? 浏览器内部的一些内部存储?)

它取自表单所在文档的基本 URI。

(顺便说一句:您正在查看绝对规范;相关规范是 RFC 7230)。

http://www.w3.org/TR/html401/struct/links.html#edef-BASE

” 12.4.1 解析相对 URI

用户代理必须根据 [RFC1808], section 3. The following describes how [RFC1808] 计算用于解析相对 URI 的基本 URI,特别适用于 HTML。

用户代理必须根据以下优先级(从最高优先级到最低优先级)计算基本 URI:

  1. 基本 URI 由 BASE 元素设置。
  2. 基本 URI 由协议期间发现的元数据给出 交互,例如 HTTP header(参见 [RFC2616])。
  1. By default, the base URI is that of the current document. Not all HTML documents have a base URI (e.g., a valid HTML document may appear in an email and may not be designated by a URI). Such HTML documents are considered erroneous if they contain relative URIs and rely on a default base URI.

<a href=""/> 中定义的

www.anotherebsite.com/action_page.php 被称为浏览器的相对 link。 因此,单击浏览器不会更新它发送请求的主机。

但是 http://www.anotherebsite.com/action_page.php 是浏览器的远程地址,并在单击时更新主机并将客户端导航到远程地址。

用户代理是连接到服务器以发送和接收来自客户端的请求的浏览器或应用程序。用户代理的示例是浏览器,如 Firefox、IE、Chrome。 每次当用户 agent/browser 希望显示特定页面时,它会向服务器发送请求以获取该内容。并且服务器响应它想要的方式(通常)。然后服务器将请求的数据作为文本发送到浏览器的 ip,并通过路由器等导航到客户端。在接收到文本时,浏览器会根据用户界面的 HTML 更改标记。

浏览器设计为具有本地存储空间缓存,用于存储您访问的 link、信息和其他数据,如表单数据、window 内容、密码和历史记录等

GET http://null.jsbin.com/GetSomething HTTP/1.1
Host: null.jsbin.com

在这里浏览器请求主机(null.jsbin.com)发送(GetSomething) 数据发送到 "null.jsbin.com" 请求 "GetSomething"

服务器通过跟随来识别浏览器

  • Cookies(存储在客户端,稍后可以检索)
  • IP 地址
  • 浏览器指纹

这里有一种方法可以检查 Web 服务器 https://panopticlick.eff.org/index.php?action=log&js=yes 实际上可以从您的浏览器检索到哪些数据。该数据可用于浏览器指纹识别,以通过服务器识别浏览器。

正如网络模型所说的持久(连接可能不是真正持久的,因为页面已经加载,但是作为 IP 地址和上面提到的其他标识符,服务器知道它是同一个 browser/user 代理相同的 session) 连接通过 session 层在客户端和服务器之间进行管理。服务器通过握手时获取的数据了解其客户端。然后它可以知道为每个客户端彻底实例化一个 session id 并且还可以通过客户端可以记住的 cookie