How does a browser know which response belongs to which request?
Today I knows that the server never send a request to a client! It just make response~
So,if the browser always want to get the newest data in the Server, it must regularly send request(always by AJAX) to the Server to get the resouce.
There comes to a important problem: when AJAX is communicting in the background,How does the browser know which response belongs to which request???
from StackOverFlow,I got an excellent answer! 阮一峰的文章也给了很多启发。
A browser can open one or more connections to a web server in order to request resources. For each of those connections the rules regarding HTTP keep-alive are the same and apply to both HTTP 1.0 and 1.1:
If HTTP keep-alive is off, the request is sent by the client, the response is sent by the server, the connection is closed:
Connection 1: [Open][Request1][Response1][Close]
If HTTP keep-alive is on, one "persistent" connection can be reused for succeeding requests. The requests are still issued serially over the same connection, so:
Connection 1: [Open][Request1][Response1][Request3][Response3][Close]
Connection 2: [Open][Request2][Response2][Request4][Response4][Close]
With HTTP Pipelining, introduced with HTTP 1.1, if it is enabled (on most browsers it is by default disabled, because of buggy servers), browsers can issue requests after each other without waiting for the response, but the responses are still returned in the same order as they were requested.
This can happen simultaneously over multiple (persistent) connections:
Connection 1: [Open][Request1][Request2][Response1][Response2][Close]
Connection 2: [Open][Request3][Request4][Response3][Response4][Close]
Both approaches (keep-alive and pipelining) still utilize the default "request-response" mechanism of HTTP: each response will arrive in the order of the requests on that same connection. They also have the "head of line blocking" problem: if [Response1]
is slow and/or big, it holds up all responses that follow on that connection.
Enter HTTP 2 multiplexing: What is the difference between HTTP/1.1 pipelining and HTTP/2 multiplexing?. Here, a response can be fragmented, allowing a single TCP connection to transmit fragments of different requests and responses intermingled:
Connection 1: [Open][Rq1][Rq2][Resp1P1][Resp2P1][Rep2P2][Resp1P2][Close]
It does this by giving each fragment an identifier to indicate to which request-response pair it belongs, so the receiver can recompose the message.
How does a browser know which response belongs to which request?的更多相关文章
- Response ServletContext 中文乱码 Request 编码 请求行 共享数据 转发重定向
Day35 Response 1.1.1 ServletContext概念 u 项目的管理者(上下文对象),服务器启动时,会为每一个项目创建一个对应的ServletContext对象. 1.1.2 ...
- response.sendRedirect(url)与request.getRequestDispatcher(url).forward(request,response)的区别
response.sendRedirect(url)跳转到指定的URL地址,产生一个新的request,所以要传递参数只有在url后加参数,如: url?id=1.request.getRequest ...
- 黑马程序员IDEA版JAVA基础班\JavaWeb部分视频\2-10Request和Response\第5节 request登录案例
用户登录案例需求: 1.编写login.html登录页面 username & password 两个输入框 2.使用Druid数据库连接池技术,操作mysql,day14数据库中user表 ...
- Explain in detail the steps/processes that occur from the moment you type a URL in a browser and hit enter
In an extremely rough and simplified sketch, assuming the simplest possible HTTP request, no proxies ...
- net1:post,get方式传值,读写cookie,读XML文件,写script语句,跳转页面,response与request类
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- request 对象和 response 对象
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象 HttpServletResponse HttpServletR ...
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
Servlet中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳 ...
- 过滤器中的chain.doFilter(request,response)
Servlet中的过滤器Filter是实现了javax.servlet.Filter接口的服务器端程序,主要的用途是过滤字符编码.做一些业务逻辑判断等.其工作原理是,只要你在web.xml文件配置好要 ...
- Response.Redirect()、Server.Execute和Server.Transfer的区别
1.Response.Redirect(): Response.Redirect方法导致浏览器链接到一个指定的URL. 当Response.Redirect()方法被调用时,它会创建一个应答,应答头中 ...
随机推荐
- python数据分析与应用
python数据分析与应用笔记 使用sklearn构建模型 1.使用sklearn转换器处理数据 import numpy as np from sklearn.datasets import loa ...
- Flask-login Question
1 未登录访问鉴权页面如何处理? 如果未登录访问了一个作了 login_required 限制的 view,那么 Flask-Login 会默认 flash一条消息,并且将重定向到login_view ...
- 冲刺阶段——Day1
[成员分工及任务量] 成员 分工 任务量(小时) 王梓鸿 完成页面设计并编写输入输出图形界面,部分代码测试 20 童皓祯 编写注册和登录模块代码,部分代码测试 20 林郅聪 绘制燃尽图,程序功能整合及 ...
- Mac 内存清理
1.清理前后的对比 清理前: 清理后: 内存多了20G 2.思路 首先,我先看了很多人的经验贴,按照他们的路子查到最后,并没有找到他们指出的大文件. 很显然,Mac的使用方式不同,其内存分配肯定也会不 ...
- fork() 成为负担,需要淘汰 spawn
A fork() in the road - Microsoft Research https://www.microsoft.com/en-us/research/publication/a-for ...
- UML期末复习题——2.4:Domain Model
第四题:领域模型 重要概念: 1. 领域模型:是对领域内的概念类或现实世界中对象的可视化表示.领域模型也称为概念模型,领域对象模型和分析对象模型. 2. 应用UML表示法,领域模型被描述为一组没有定义 ...
- leetcode 96. Unique Binary Search Trees 、95. Unique Binary Search Trees II 、241. Different Ways to Add Parentheses
96. Unique Binary Search Trees https://www.cnblogs.com/grandyang/p/4299608.html 3由dp[1]*dp[1].dp[0]* ...
- 关于axios如何在请求头添加参数
vm.$http.post(apiUrl.refundOrder, data,{ headers:{ 'lz-shopid':vm.orderRecords.shopId } }).then(res ...
- linux:解决SSH连接Linux超时自动断开
用SSH登录到Linux的时候,由于默认的连接超时时间很短,经常断开! 1.修改文件 # vi /etc/ssh/sshd_config 2.重启sshd服务 # /etc/init.d/sshd r ...
- 005-多线程-锁-JUC锁-LockSupport【使用、Unsafe、对比Object的wait、底层源码】
一.概述 在Java多线程中,当需要阻塞或者唤醒一个线程时,都会使用LockSupport工具类来完成相应的工作.LockSupport定义了一组公共静态方法,这些方法提供了最基本的线程阻塞和唤醒功能 ...