首页 > 解决方案 > HTTP 标头是用什么语言编写的?

问题描述

以下是 HTTP 标头。这段代码是用什么语言或语法编写的?

HTTP/2.0 200 OK
Content-type: text/html
Set-Cookie: yummy_cookie=choco
Set-Cookie: tasty_cookie=strawberry

它不是 JavaScript 或 PHP。这是取自https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies的另一个示例

GET /sample_page.html HTTP/2.0
Host: www.example.org
Cookie: yummy_cookie=choco; tasty_cookie=strawberry

标签: httphttprequest

解决方案


它们是 HTTP 事实标准定义的一部分,被编入所谓的 RFC 或 Request For Comments。RFC 是关于人们所知的 Internet 基础的事实标准的集合。

https://www.rfc-editor.org/rfc/rfc2616#page-31

4.2 消息头

HTTP 头字段,包括 general-header(第 4.5 节)、request-header(第 5.3 节)、response-header(第 6.2 节)和 entity-header(第 7.1 节)字段,遵循与第 7.1 节中给出的相同的通用格式RFC 822 [9] 的 3.1。每个标头字段由一个名称后跟一个冒号(“:”)和字段值组成。字段名称不区分大小写。字段值可以在任意数量的 LWS 之前,但最好使用单个 SP。通过在每个额外行之前至少使用一个 SP 或 HT,标题字段可以扩展到多行。在生成 HTTP 结构时,应用程序应该遵循已知或指示的“通用形式”,因为可能存在一些无法接受超出通用形式的任何实现的实现。

message-header = field-name ":" [ field-value ]
field-name     = token
field-value    = *( field-content | LWS )
field-content  = <the OCTETs making up the field-value
                 and consisting of either *TEXT or combinations
                 of token, separators, and quoted-string>

推荐阅读