HTTP规范中关于消息的header头部
HTTP中的header头部
包括通用头部(general-header)、请求头部(request-header)、响应头部(response-header)、实体头部(entity-header)。
这些header头部都采用通用的格式定义。
header头不只是存在消息的请求或响应中的头部域,还可能存在在消息体(实体体)中。如下一次请求多个分段的例子中:
请求中指定Range头字段:
Range:bytes=0-2,3-\r\n
响应:
--00000000001
Content-Type: text/html
Content-Range: bytes 0-2/151
<ht
--00000000001
Content-Type: text/html
Content-Range: bytes 3-150/151
ml>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
--00000000001--
通用头部(general-header):
general-header = Cache-Control ; Section 14.9
| Connection ; Section 14.10
| Date ; Section 14.18
| Pragma ; Section 14.32
| Trailer ; Section 14.40
| Transfer-Encoding ; Section 14.41
| Upgrade ; Section 14.42
| Via ; Section 14.45
| Warning ; Section 14.46
Transfer-Encoding通用头部:
Transfer-Encoding头部都有哪些可选值?
Transfer-Encoding头部可指定:"chunked" (section 3.6.1), "identity" (section 3.6.2), "gzip" (section 3.5), "compress" (section 3.5), and "deflate" (section 3.5).
Transfer-Encoding头部的这些可指定的值是从哪里来的?
transfer-coding value tokens. Initially, the registry contains the
following tokens: "chunked" (section 3.6.1), "identity" (section
3.6.2), "gzip" (section 3.5), "compress" (section 3.5), and "deflate"
(section 3.5).
New transfer-coding value tokens SHOULD be registered in the same way
as new content-coding value tokens (section 3.5).
以下例子如果不采用Transfer-Encoding: chunked的话,一般是这样请求的:采用Content-Type: application/x-www-form-urlencoded的Content-Type。如下:
Content-Type: application/x-www-form-urlencoded的例子:
POST /test HTTP/1.1\r\n
Host: localhost\r\n
Content-Length: 12\r\n
Content-Type: application/x-www-form-urlencoded\r\n
\r\n
data=abcdefg
响应:
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 7
Date: Fri, 22 Mar 2019 17:54:40 GMT
abcdefg
如果采用Transfer-Encoding: chunked的话:
这里采用Transfer-Encoding: chunked后,将请求参数data=abcdefg硬生生的分成4段(chunk)进行传输(实际上是3段,第4段的chunk为0表示所有的chunk都传输过去了,即结束标识),当然这里只是为了演示Transfer-Encoding: chunked的用法。
POST /test HTTP/1.1\r\n
Host: localhost\r\n
Transfer-Encoding: chunked\r\n
Content-Type: application/x-www-form-urlencoded\r\n
\r\n
2\r\n
da\r\n
5\r\n
ta=ab\r\n
5\r\n
cdefg\r\n
0\r\n
\r\n
响应:
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 7
Date: Fri, 22 Mar 2019 18:38:42 GMT
abcdefg
请求头部(request-header):
request-header = Accept ; Section 14.1
| Accept-Charset ; Section 14.2
| Accept-Encoding ; Section 14.3
| Accept-Language ; Section 14.4
| Authorization ; Section 14.8
| Expect ; Section 14.20
| From ; Section 14.22
| Host ; Section 14.23
| If-Match ; Section 14.24
| If-Modified-Since ; Section 14.25
| If-None-Match ; Section 14.26
| If-Range ; Section 14.27
| If-Unmodified-Since ; Section 14.28
| Max-Forwards ; Section 14.31
| Proxy-Authorization ; Section 14.34
| Range ; Section 14.35
| Referer ; Section 14.36
| TE ; Section 14.39
| User-Agent ; Section 14.43
Range请求头部:
例子:
一次请求一个分段的例子
请求服务端资源的前3个字节:
GET / HTTP/1.1\r\n
Host: localhost\r\n
Range:bytes=0-2\r\n
\r\n
响应:
HTTP/1.1 206 Partial Content
Server: nginx/0.8.18
Date: Fri, 22 Mar 2019 16:55:13 GMT
Content-Type: text/html
Content-Length: 3
Last-Modified: Wed, 30 Aug 2006 06:39:18 GMT
Connection: keep-alive
Content-Range: bytes 0-2/151
<ht
一次请求多个分段的例子
分2个分段请求服务端资源,第一个分段请求前3个字节,第二个分段请求从第3个字节到最后一个字节:
GET / HTTP/1.1\r\n
Host: localhost\r\n
Range:bytes=0-2,3-\r\n
\r\n
响应:
HTTP/1.1 206 Partial Content
Server: nginx/0.8.18
Date: Fri, 22 Mar 2019 17:02:17 GMT
Content-Type: multipart/byteranges; boundary=00000000001
Content-Length: 320
Last-Modified: Wed, 30 Aug 2006 06:39:18 GMT
Connection: keep-alive
--00000000001
Content-Type: text/html
Content-Range: bytes 0-2/151
<ht
--00000000001
Content-Type: text/html
Content-Range: bytes 3-150/151
ml>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
--00000000001--
完整的响应应该是:
HTTP/1.1 200 OK
Server: nginx/0.8.18
Date: Fri, 22 Mar 2019 16:58:36 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Wed, 30 Aug 2006 06:39:18 GMT
Connection: keep-alive
Accept-Ranges: bytes
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
响应头部(response-header):
response-header = Accept-Ranges ; Section 14.5
| Age ; Section 14.6
| ETag ; Section 14.19
| Location ; Section 14.30
| Proxy-Authenticate ; Section 14.33
| Retry-After ; Section 14.37
| Server ; Section 14.38
| Vary ; Section 14.44
| WWW-Authenticate ; Section 14.47
实体头部(entity-header):
entity-header = Allow ; Section 14.7
| Content-Encoding ; Section 14.11
| Content-Language ; Section 14.12
| Content-Length ; Section 14.13
| Content-Location ; Section 14.14
| Content-MD5 ; Section 14.15
| Content-Range ; Section 14.16
| Content-Type ; Section 14.17
| Expires ; Section 14.21
| Last-Modified ; Section 14.29
| extension-header
extension-header = message-header
Content-Type实体头部:
Content-Type = "Content-Type" ":" media-type
media-type = type "/" subtype *( ";" parameter )
type = token
subtype = token
parameter = attribute "=" value
attribute = token
value = token | quoted-string
关于Content-Type参考另一篇文章:https://lobin.iteye.com/blog/2342340
Content-Type: application/x-www-form-urlencoded的例子:
POST /test HTTP/1.1\r\n
Host: localhost\r\n
Content-Length: 12\r\n
Content-Type: application/x-www-form-urlencoded\r\n
\r\n
data=abcdefg
响应:
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 7
Date: Fri, 22 Mar 2019 17:54:40 GMT
abcdefg
Content-Type: multipart/form-data; boundary=m1w592WOaxybpIOCyoAg-IXoMBaAb1R9kv92的例子:
POST /test HTTP/1.1\r\n
Host: localhost\r\n
Content-Length: 205\r\n
Content-Type: multipart/form-data; boundary=m1w592WOaxybpIOCyoAg-IXoMBaAb1R9kv92\r\n
\r\n
--m1w592WOaxybpIOCyoAg-IXoMBaAb1R9kv92\r\n
Content-Disposition: form-data; name="data"\r\n
Content-Type: text/plain; charset=UTF-8\r\n
Content-Transfer-Encoding: 8bit\r\n
\r\n
aaaa\r\n
--m1w592WOaxybpIOCyoAg-IXoMBaAb1R9kv92
响应:
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 4
Date: Fri, 22 Mar 2019 17:57:19 GMT
aaaa
相关推荐
网页设计制作命名 规范 1. Container(整体) “container“ 就是将页面中的所有元素包在一起的部分,这部分还可以命名为: “wrapper“, “wrap“, “page“. 2. Header(头部) “header” 是网站页面的头部区域,一般...
头部样式用header,头部左边,可以用header_left或header_l,还有如果是列结构的可以这样——box _1of3 (三列中的第一列),box_2of3 (三列中的第二列)、box _3of3 (三列中的第三列),其它的我就不一一举例了,大家按...
采用 UTF-8 编码,在 CSS 代码头部使用: @charset utf-8; 注意,必须要定义在 CSS 文件所有字符的前面(包括编码注释),@charset 才会生效。 例如,下面的例子都会使得 @charset 失效: /* 字符编码 */ @charset ...
头部样式用header,头部左边,可以用header_left或header_l,还有如果是列结构的可以这样——box _1of3 (三列中的第一列),box_2of3 (三列中的第二列)、box _3of3 (三列中的第三列),其它的我就不一一举例了,大家按...
为了开发后样式名管理方便,大家请用有意义的单词或缩写组合来命名,让同事一看就明白这样式大概是哪一块的,这样就节省了查找样式的时间,例如: 头部样式用header,头部左边,可以用header_left或header_l,还有...
为了开发后样式名管理方便,大家请用有意义的单词或缩写组合来命名,让同事一看就明白这样式大概是哪一块的,这样就节省了查找样式的时间,例如: 头部样式用header,头部左边,可以用header_left或header_l,还有...
1、定义 header()头部输出格式 header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=php100.xls"); 2、输出编码和支持的格式 (1)支持普通格式的CSV 文本规范,以空格和...
(第47讲) PHP输出CSV和EXCEL两种简单的方法1、定义 header()头部输出格式header("Content-typefilename=php100.xls");2、输出编码和支持的格式(1)支持普通格式的CSV 文本规范,以空格和换行来识别(2)支持简单...
JSON Web Token(JWT)是一个非常轻巧的规范。这个规范允许我们使用JWT在用户和服务器之间传递安全可靠的信息...一个JWT实际上就是一个字符串,它由三部分组成,头部(header)、载荷(playload)与签名(signature)。
一个JWT由三部分组成,Header头部、Claims载荷、Signature签名, JWT原理类似我们加盖公章或手写签名的的过程,合同上写了很多条款,不是随便一张纸随便写啥都可以的,必须要一些证明,比如签名,比如盖章,JWT就是通过附加...
1、编写一对 body 标记,在body标记中,嵌套一对 div标记,在 div 标记中 ,嵌套一对 a 标记,在 a标记中,嵌套一对 b 标记,b标记中,随意编写一些文本 <body> 这是一段测试文本 </body> ...
属于物理层定义的典型规范代表包括:EIA/TIA RS-232、EIA/TIA RS-449、V.35、RJ-45等。 2、数据链路层(Data Link Layer) 数据链路层在不可靠的物理介质上提供可靠的传输。该层的作用包括:物理地址寻址、...
CSS语义化命名 从上图我们可以大概看出这里有两种CSS的命名方式:1、结构化命名法;...语义化命名法:根据页面中模块的功能而命名,如页面头部header、导航栏nav、主体main、侧边栏sidebar、底部footer、新
比如头部(header)、尾部(footer)、搜索框(searchbar)、导航(menu)、对话框(dialog)等,甚至一些复杂的组件比如编辑器(editor)等。通常业务会针对组件化的js部分进行必要的封装,解决一些常见的组件渲染、交互问题。...
前言 最近公司项目进行架构...最开始通过头部(Header)将Cookies传输到其WebAPI,也能解决问题。 下面讲述另外一种解决方案。 解决过程: 步骤一:将Cookies的Domain(域)设置成一级域名,例如:“.wbl.com”(a.w
web1000A Vue.js project项目目录结构|-- src // 源码目录| |-- components // 功能组件| |-- common // 公共组件| |-- footer // 分模块--底部公共组件| |-- header // 分模块--头部公共组件|| |-- config // 基本...