http请求Response Headers作用

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers

以下面实际请求为例进行说明

access-control-allow-credentials: true
access-control-allow-headers: Client-Userid,Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With, Form-type
access-control-allow-methods: GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE
access-control-allow-origin: *
access-control-expose-headers: Server
access-control-max-age: 1728000
cache-control: max-age=43200
cache-control: no-cache
content-type: application/json; charset=utf-8
date: Mon, 15 Aug 2022 12:40:33 GMT
expires: Tue, 16 Aug 2022 00:40:33 GMT
server: nginx
set-cookie: think_lang=zh-cn; path=/
set-cookie: PHPSESSID=1fece81b6053c6557f0ccfa8ff614270; path=/
x-cache: MISS

 

1、Access-Control-Expose-Headers

响应首部 Access-Control-Expose-Headers 列出了哪些首部可以作为响应的一部分暴露给外部。

默认情况下,只有七种 simple response headers(简单响应首部)可以暴露给外部:

  •     Cache-Control
  •     Content-Language
  •     Content-Length
  •     Content-Type
  •     Expires
  •     Last-Modified
  •     Pragma

如果想要让客户端可以访问到其他的首部信息,可以将它们在 Access-Control-Expose-Headers 里面列出来。

Access-Control-Expose-Headers: Content-Length

 

2、Access-Control-Allow-Credentials

Access-Control-Allow-Credentials 响应头告知浏览器是否可以将对请求的响应暴露给前端 JavaScript 代码。

Access-Control-Allow-Credentials: true

 

3、Access-Control-Allow-Headers

响应首部 Access-Control-Allow-Headers 列出了将会在正式请求的 Access-Control-Request-Headers 字段中出现的首部信息。

Access-Control-Allow-Headers: <header-name>[, <header-name>]*
Access-Control-Allow-Headers: *

 自定义的请求头

下面是 Access-Control-Allow-Headers 标头的一个示例。 它表明,除了 CORS 安全清单列出的请求标头外,对服务器的 CORS 请求还支持名为 X-Custom-Header 的自定义标头。

Access-Control-Allow-Headers: X-Custom-Header

 

4、Access-Control-Allow-Methods

响应首部 Access-Control-Allow-Methods 明确客户端所要访问的资源允许使用的方法或方法列表。

Access-Control-Allow-Methods: POST, GET, OPTIONS

 

5、Access-Control-Allow-Origin

Access-Control-Allow-Origin 响应头指定该响应的资源是否被允许与给定的origin共享。

Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: https://developer.mozilla.org

 

7、Access-Control-Max-Age

Access-Control-Max-Age 响应头表示返回结果(即 Access-Control-Allow-MethodsAccess-Control-Allow-Headers 提供的信息) 可以被缓存多久。

Access-Control-Max-Age: 600

 

8、Access-Control-Request-Headers

Access-Control-Request-Headers用于通知服务器在真正的请求中会采用哪些请求头。

Access-Control-Request-Headers: X-PINGOTHER, Content-Type

 

9、Access-Control-Request-Method

Access-Control-Request-Method 用于通知服务器在真正的请求中会采用哪种 HTTP 方法。这个请求头是必要的。

Access-Control-Request-Method: POST

 

10 、Accept-Charset

 Accept-Charset 请求头用来告知(服务器)客户端可以处理的字符集类型。

Accept-Charset: iso-8859-1

Accept-Charset: utf-8, iso-8859-1;q=0.5

Accept-Charset: utf-8, iso-8859-1;q=0.5, *;q=0.1

 

11、Accept-Encoding

HTTP 请求头 Accept-Encoding 会将客户端能够理解的内容编码方式——通常是某种压缩算法——进行通知(给服务端)。

即使客户端和服务器都支持相同的压缩算法,在 identity 指令可以被接受的情况下,服务器也可以选择对响应主体不进行压缩。导致这种情况出现的两种常见的情形是:

  • 要发送的数据已经经过压缩,再次进行压缩不会导致被传输的数据量更小。一些图像格式的文件会存在这种情况;
  • 服务器超载,无法承受压缩需求导致的计算开销。通常,如果服务器使用超过 80% 的计算能力,微软建议不要压缩。
Accept-Encoding: gzip
Accept-Encoding: compress
Accept-Encoding: deflate
Accept-Encoding: br
Accept-Encoding: identity
Accept-Encoding: *
Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5

 

12、Expires

Expires 响应头包含日期/时间, 即在此时候之后,响应过期。无效的日期,比如 0,代表着过去的日期,即该资源已经过期。
如果在Cache-Control响应头设置了 "max-age" 或者 "s-max-age" 指令,那么 Expires 头会被忽略。
Expires: Wed, 21 Oct 2015 07:28:00 GMT

 

13、Origin

请求标头 Origin 表示了请求的来源(协议、主机、端口)。

例如,如果一个用户代理需要请求一个页面中包含的资源,或者执行脚本中的 HTTP 请求(fetch),那么该页面的来源(origin)就可能被包含在这次请求中。

Origin: http://developer.mozilla.org:80

 

14、Cache-Control

Cache-Control 通用消息头字段,被用于在 http 请求和响应中,通过指定指令来实现缓存机制。缓存指令是单向的,这意味着在请求中设置的指令,不一定被包含在响应中。

缓存请求指令

客户端可以在 HTTP 请求中使用的标准 Cache-Control 指令。

Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-control: no-cache
Cache-control: no-store
Cache-control: no-transform
Cache-control: only-if-cached

缓存响应指令

服务器可以在响应中使用的标准 Cache-Control 指令。

Cache-control: must-revalidate
Cache-control: no-cache
Cache-control: no-store
Cache-control: no-transform
Cache-control: public
Cache-control: private
Cache-control: proxy-revalidate
Cache-Control: max-age=<seconds>
Cache-control: s-maxage=<seconds>

 

15、Connection

Connection 头(header) 决定当前的事务完成后,是否会关闭网络连接。如果该值是“keep-alive”,网络连接就是持久的,不会关闭,使得对同一个服务器的请求可以继续在该连接上完成。

Connection: keep-alive
Connection: close

 

16、Content-Type

Content-Type 实体头部用于指示资源的 MIME 类型 media type 。

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something

 

17、Cookie

Cookie 是一个 HTTP 请求标头,其中含有先前由服务器通过 Set-Cookie 标头投放或通过 JavaScript 的 Document.cookie 方法设置,然后存储到客户端的 HTTP cookie 。

Cookie: PHPSESSID=2981zf09hf012fh2; csrftoken=u32t124o3tb3gg43; _gat=13

 

18、Server

Server 首部包含了处理请求的源头服务器所用到的软件相关信息。
应该避免使用过长或者过于详细的描述作为 Server 的值,因为这有可能泄露服务器的内部实现细节,有利于攻击者找到或者探测已知的安全漏洞。

Server: Apache/2.4.1 (Unix)

 

19、User-Agent

User-Agent 首部包含了一个特征字符串,用来让网络协议的对端来识别发起请求的用户代理软件的应用类型、操作系统、软件开发商以及版本号。

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
posted @ 2022-08-17 00:53  使用D  阅读(549)  评论(0编辑  收藏  举报