Skip to main content

Http1.1

问题

http 1.1 中的 keep-alive 有什么作用

在 http 1.1 中,在响应头中设置 keep-alive 可以在一个 TCP 连接上发送多个 http 请求

避免了重开 TCP 连接的开销 避免了刷新时重新建立 SSL 连接的开销 避免了 QPS 过大时,服务器的连接数过大 在服务器端使用响应头开启 keep-alive

Connection: Keep-Alive
Keep-Alive: timeout=5, max=1000

既然 http 是无状态协议,那它是如何保持登录状态

通过 cookie 或者 Authorization header 来传递凭证,在服务端进行认证