浏览器如何检测哪些HTTP响应是他们的? [英] How do browsers detect which HTTP response is theirs?

查看:99
本文介绍了浏览器如何检测哪些HTTP响应是他们的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于您运行了多个Web浏览器,显然所有这些都在端口80上进行侦听,如果传入的HTTP响应是由自身发起的,浏览器将如何计算?是否捕获响应并显示它?

Given that you have multiple web browsers running, all which obviously listen on port 80, how would a browser figure if an incoming HTTP response was originated by itself? And whether or not catch the response and show it?

推荐答案

作为连接过程的一部分,为TCP / IP连接分配了一个客户端端口。浏览器侦听端口80;而是浏览器向服务器上的[服务器]端口80发起请求,并等待来自服务器IP的客户端端口的回复。

As part of the connection process a TCP/IP connection is assigned a client port. Browsers do not "listen on port 80"; rather a browser initiate a request to [server] port 80 on the server and waits for a reply on the client port from the server's IP.

分配客户端端口后(本地),每个客户端[TCP / IP]连接由(服务器IP,服务器端口,客户端IP,客户端端口) 唯一标识,并且连接(以及通过这种方式发送的响应)可以连接回到正确的浏览器。这个相同的连接识别元组是服务器如何不混淆来自同一客户端/ IP的多个请求 1

After the client port is assigned (locally), each client [TCP/IP] connection is uniquely identified by (server IP, server port, client IP, client port) and the connection (and response sent over such) can be "connected back" to the correct browser. This same connection-identifying tuple is how a server doesn't confuse multiple requests coming from the same client/IP1

HTTP位于顶部TCP / IP层,并且不必关心混合连接流。 ( HTTP / 2引入了多路复用,但这是一个不同的野兽,只有影响来自同一浏览器的连接。)

HTTP sits on top of the TCP/IP layer and doesn't have to concern itself with mixing up connection streams. (HTTP/2 introduces multiplexing, but that is a different beast and only affects connection from the same browser.)

参见短暂的端口范围概述:


TCP / IPv4连接由两个端点组成,每个端点由IP地址和端口号组成。因此,当客户端用户连接到服务器计算机时,已建立的连接可以被认为是(服务器IP,服务器端口,客户端IP,客户端端口)的4元组。通常是三个很容易知道四个 - 客户端机器使用自己的IP地址,当连接到远程服务时,服务器机器的IP地址和服务端口号是必需的 [只保留客户端端口未知并自动分配]。

A TCP/IPv4 connection consists of two endpoints, and each endpoint consists of an IP address and a port number. Therefore, when a client user connects to a server computer, an established connection can be thought of as the 4-tuple of (server IP, server port, client IP, client port). Usually three of the four are readily known -- client machine uses its own IP address and when connecting to a remote service, the server machine's IP address and service port number are required [leaving only the client port unknown and to be automatically assigned].

当建立连接时,连接的客户端使用端口号时,不明显。除非客户端程序显式请求特定的端口号,使用的端口号是短暂的端口号。 临时端口是由机器的IP堆栈分配的临时端口,并且为此目的从指定范围的端口分配。当连接终止时,临时端口可用于重用,尽管大多数IP堆栈已赢得重新使用该端口号,直到使用了整个临时端口池。因此,如果客户端程序重新连接,将为其新连接的一侧分配一个不同的临时端口号。

What is not immediately evident is that when a connection is established that the client side of the connection uses a port number. Unless a client program explicitly requests a specific port number, the port number used is an ephemeral port number. Ephemeral ports are temporary ports assigned by a machine's IP stack, and are assigned from a designated range of ports for this purpose. When the connection terminates, the ephemeral port is available for reuse, although most IP stacks won't reuse that port number until the entire pool of ephemeral ports have been used. So, if the client program reconnects, it will be assigned a different ephemeral port number for its side of the new connection.

参见< a href =http://www.tcpipguide.com/free/t_TCPIPClientEphemeralPortsandClientServerApplicatio.htm =noreferrer> TCP / IP客户端(临时)端口和客户端/服务器应用程序端口使用以获得额外的温和解释:

See TCP/IP Client (Ephemeral) Ports and Client/Server Application Port Use for an additional gentle explanation:


要知道在何处发送回复,服务器必须知道客户端正在使用的端口号。 此客户端端口由客户端作为请求中的源端口提供,然后由服务器用作发送回复的目标端口。客户端进程不使用众所周知的或注册港口。而是为每个客户端进程分配一个临时端口号供其使用。这通常称为短暂的端口号。

To know where to send the reply, the server must know the port number the client is using. This [client port] is supplied by the client as the Source Port in the request, and then used by the server as the destination port to send the reply. Client processes don't use well-known or registered ports. Instead, each client process is assigned a temporary port number for its use. This is commonly called an ephemeral port number.






1 如果有多个客户端计算机(即不同的TCP / IP堆栈,每个都分配可能重复的短暂端口)使用相同的外部IP,那么像网络地址转换,因此服务器仍然每个连接都有一个唯一的元组:


1 If there are multiple client computers (ie. different TCP/IP stacks each assigning possibly-duplicate ephemeral ports) using the same external IP then something like Network Address Translation must be used so the server still has a unique tuple per connection:


网络地址转换(NAT)是一种在互联网协议(IP)数据报包头中修改网络地址信息的方法,它们在流量路由设备中传输,以便将一个IP地址空间重新映射到另一个IP地址空间。

Network address translation (NAT) is a methodology of modifying network address information in Internet Protocol (IP) datagram packet headers while they are in transit across a traffic routing device for the purpose of remapping one IP address space into another.

这篇关于浏览器如何检测哪些HTTP响应是他们的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆