Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HTTP-响应Header

Access相关

  • Access-Control-Allow-Origin

    // 该资源可以被所有网站跨域共享
    // 设置后,Access-Control-Allow-Credentials就不能为true
    Access-Control-Allow-Origin: *
    
    // 该资源仅能被指定网站跨域共享
    Access-Control-Allow-Origin: juejin.cn
    
  • Access-Control-Allow-Methods

    // 允许哪些访问方法
    Access-Control-Allow-Methods:GET,OPTION,HEAD,PUT,POST
    
  • Access-Control-Allow-Credentials

    // 服务器允许浏览器进行cookie发送
    // 只能为true,如果不允许,不设置该字段即可
    Access-Control-Allow-Credentials: true
    

Content相关

  • Content-length

    //此次响应内容的长度
    Content-length: 643
    
  • Content-type

    //此次响应内容的格式以及编码
    Content-type: text/plain;charset=UTF-8
    

缓存相关

  • Expires(http1.0引入)

    // 在这个时间前,缓存是有效的
    Expires: Sat, 14 Jan 2023 05:12:43 GMT
    
    // 不缓存
    Expires: 0
    
  • Cache-control(http1.1引入,较先进)

    // 默认值,响应只能被浏览器缓存
    Cache-Control:private
    
    // 浏览器和缓存服务器都可以缓存
    Cache-Control:public
    
    // 浏览器缓存,且10秒钟内有效
    Cache-control: max-age=10
    
    // 所有内容都不会缓存,即不用强缓存,也不用协商缓存
    Cache-control: no-store
    
    // 注意,还是会用缓存,只是需要协商缓存确认
    Cache-control: no-cache
    
    // 对于每次请求,代理服务器必须向服务器验证缓存是否过时
    Cache-control: must-revalidate
    
  • Last-Modified(http1.0引入)

    // 响应资源的最后修改日期,如果没变,则服务器返回304,直接用之前的缓存
    Last-Modified: Sat, 14 Jan 2023 05:12:43 GMT
    
  • Etag(http1.1引入,较先进)

    // 响应资源的哈希,如果没变,则服务器返回304,直接用之前的缓存
    ETag: "737060cd8c284d8af7ad3082f209582d"
    

其他

  • Date

    // 服务端响应资源时的服务器时间,是0时区格林尼治GMT时间
    Date: Sat, 14 Jan 2023 05:12:43 GMT
    
  • Server

    // 服务器内提供响应的服务名
    Server: nginx