`
lobin
  • 浏览: 417728 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

HTTP规范中关于消息的header头部

 
阅读更多

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头部的这些可指定的值是从哪里来的?

写道
The Internet Assigned Numbers Authority (IANA) acts as a registry for
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

 

 

 

 

 

0
0
分享到:
评论

相关推荐

    header和meta头部信息

    这篇博文链接指向的是一个关于`header`和`meta`头部信息的讨论,虽然具体内容无法直接提供,但从一般意义上,我们可以深入探讨这两个关键元素的作用、用途以及相关知识点。 `&lt;header&gt;` 标签: 1. **定义页面头部**...

    C# 源文件 Header 设计

    总之,"C# 源文件 Header 设计" 是一个关于在C#编程中创建和维护代码文件头部注释的实践,它涉及到了代码管理和团队协作的最佳实践。通过利用MSDN上的资源,开发者可以学习并实现自定义的头部注释生成工具,从而提高...

    前端开源库-auth-header

    开发者可以通过简单的API调用,快速设置或获取认证头,使得在前端代码中处理认证变得更加简单和规范化。 例如,使用`auth-header`库设置一个Basic Auth的认证头: ```javascript const authHeader = require('auth...

    PHP 常用的header头部定义汇总

    `header()` 函数是 PHP 中用于向客户端发送原始 HTTP 头部信息的关键函数。它允许开发者控制页面的响应状态、重定向、设置缓存策略、指定文档类型等。以下是对 `header()` 函数常用用途的详细说明: 1. **响应状态...

    HTTP1.1协议规范(中文归纳版)

    - **MUST / SHOULD / RECOMMENDED / MAY / OPTIONAL**:这些词汇用来表示规范中的约束级别。 - **MUST**:必须实现。 - **SHOULD**:建议实现但可以忽略。 - **MAY**:可选实现。 - **Connection (连接)**:...

    soap规范web service调用

    - 使用HTTP时,SOAP消息通常被封装在HTTP请求体中,并且HTTP响应也会包含一个SOAP消息。 综上所述,SOAP作为一种标准的协议,为Web服务之间的通信提供了统一的框架。通过对SOAP的基本规范、消息结构、编码规则及...

    Web UI 设计命名规范讲解

    2. Header(头部):网站页面的头部区域,一般包含网站的 logo 和一些其他元素,可以命名为“page-header”(或 pageHeader)。 3. Navbar(导航栏):横向的导航栏,是最典型的网页元素,可以命名为“nav”、...

    VSCode中自动为Python文件添加头部注释

    保存修改后的json文件后,用户在新建一个Python文件并在文件顶部输入定义好的前缀“header”,VSCode就会自动弹出预定义的头部注释模板。用户只需根据实际需要稍作修改即可。 如果用户希望修改头部注释的模板内容,...

    浅析HTML5中header标签的用法

    在这个例子中,我们看到&lt;header&gt;标签不仅用于页面的整体头部,还用于文章的头部。每个&lt;header&gt;都包含了文章或区块的标题和简介信息。 在HTML5中,&lt;header&gt;标签的灵活性非常高,可以在页面的任何位置使用,不仅限于...

    SOAP协议规范详解

    SOAP协议规范详细地定义了消息格式、处理规则以及错误处理机制,确保了跨平台、跨语言的互操作性。 SOAP消息的核心是XML文档,它由一系列的元素组成,包括`Envelope`、`Header`和`Body`。`Envelope`元素是SOAP消息...

    addheader.rar_SEG-Y

    在SEG-Y格式中,头部信息非常重要,因为它包含了关于数据采集、处理和解释的重要细节,例如: 1. **数据记录布局**:说明每个样本的位数,是单精度还是双精度浮点数,以及数据的排列顺序(例如,是大端序还是小端序...

    SOAP协议规范(中文版).doc

    6. **HTTP中的SOAP**:SOAP通常在HTTP上运行,HTTP提供了可靠的消息传输和错误处理机制。HTTP头中的`SOAPAction`域用于指示请求的Web服务操作。SOAP HTTP请求和响应分别有自己的格式要求。 7. **RPC(Remote ...

    前端开源库-gulp-headerfooter

    而`gulp-headerfooter`是一个专门为Gulp设计的插件,它的主要功能是向文件添加页眉和页脚内容,这对于维护代码规范和版权信息非常有用。 `gulp-headerfooter`库的使用非常简单,首先你需要确保已经安装了Gulp。如果...

    AHCI1.3.1规范

    1. PCI头部寄存器(PCI Header):定义了控制器的硬件设备ID、命令/状态寄存器、修订版本ID、类别代码等基本信息。 2. AHCI基地址寄存器(AHCIBaseAddress):用于确定AHCI控制器的内存地址范围,以便系统访问。 3...

    网页设计制作命名 规范

    网页设计制作命名 规范 1. Container(整体) “container“ 就是将页面中的所有元素包在一起的部分,这部分还可以命名为: “wrapper“, “wrap“, “page“. 2. Header(头部) “header” 是网站页面的头部区域,一般...

    Web网页设计命名规范

    2. Header:网站的头部区域,包含网站的logo和其他元素,命名可为“header”、“page-header”等。 3. Navbar:横向的导航栏,是最典型的网页元素,命名可为“navbar”、“nav”、“navigation”等。 4. Menu:...

    swift-http-structured-header:HTTP结构化标头字段规范的Swift实现

    Swift中的HTTP结构化标头字段规范实现了HTTP协议中定义的复杂标头处理,这使得开发者在处理具有多种数据类型的HTTP头部信息时更加便捷和安全。本文将深入探讨这个Swift库的功能、用途以及如何使用它来增强你的HTTP...

    前端CSS规范整理.doc

    前端开发中,CSS的组织和编写规范对于代码的可读性、维护性和团队协作至关重要。本文主要围绕文件规范、注释规范以及命名规范三个方面,梳理了前端CSS规范的重要内容。 一、文件规范 1. 文件组织结构:CSS文件需...

    前端开源库-eslint-plugin-flow-header

    总结来说,`eslint-plugin-flow-header`是一个提升前端开发效率和代码质量的实用工具,它与`ESLint`和`Flow`结合,强制执行文件头部的`Flow`注释规范,从而确保了代码的类型安全性和一致性。对于使用`Flow`进行类型...

    自动根据模板插入header、body内容插件

    标题中的“自动根据模板插入header、body内容插件”指的是一个用于Visual Studio Code(VSC)的扩展插件,它的主要功能是自动化地在代码文件中插入预定义的header和body部分。这样的插件对于软件开发团队尤其有用,...

Global site tag (gtag.js) - Google Analytics