HTTP协议原理

HTTP协议原理

1. HTTP浏览器输入URL后HTTP请求返回的完整过程

浏览器请求过程

2. HTTP2新功能
  • 所有数据以二进制传输
  • 同一个连接里面发送多个请求,不再需要按照顺序来
  • 头信息压缩以及推送等提高效率的功能
3. URI、URL、URN

URI : Uniform Resource Identifier 统一资源标志符
用来唯一标识互联网上的信息资源,包括URL和URN

URL: Uniform Resource Locator 统一资源定位符

URN: 永久统一资源定位符

4. 浏览器缓存

浏览器发送请求到查找缓存的过程

5. Cookie和Session
  1. Cookie
  • 通过set-cookie设置
  • 下次请求会自动带上
  • 键值对,可设置多个
  • max-age和expires设置过期时间
  • Secure 只在https的时候发送
  • HttpOnly 无法通过document.cookie访问
const http = require('http')
const fs = require('fs')

http.createServer(function (request, response) {
  console.log('request come', request.url)

  if (request.url === '/') {
    const html = fs.readFileSync('test.html', 'utf8')
    response.writeHead(200, {
      'Content-Type': 'text/html',
      'Set-Cookie': ['id=123; max-age=2', 'abc=456;domain=test.com'] //设置cookie
    })
    response.end(html)
  }

}).listen(8887)

console.log('server listening on 8887')
6. HTTP长连接
const http = require('http')
const fs = require('fs')

http.createServer(function (request, response) {
  console.log('request come', request.url)

  const html = fs.readFileSync('test.html', 'utf8')
  const img = fs.readFileSync('test.jpg')
  if (request.url === '/') {
    response.writeHead(200, {
      'Content-Type': 'text/html',
    })
    response.end(html)
  } else {
    response.writeHead(200, {
      'Content-Type': 'image/jpg',
      // 'Connection': 'keep-alive' 
      'Connection': 'close'
    })
    response.end(img)
  }

}).listen(8888)

console.log('server listening on 8888')
7. CSP

Content-Security-Policy 内容安全策略
作用:限制资源获取
限制方式 :default-src限制全局
根据资源类型限制:connect-src、img-src、 font-src等等。。。

8.HTTPS

HTTPS加密传输过程
HTTPS加密传输过程

9. HTTP2

优势:

  • 信道复用
  • 分帧传输:每一帧都有上下文的联系,也就是说通过HTTP发送的数据并不需要一定要按照严格的顺序发送;同一个连接上并发地发送不同的请求
  • Server Push
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值