严重疏漏:request 返回的 header 是个结构体???
发布于 6 年前 作者 nxiang 17697 次浏览 来自 问答

在 HTTP 协议中,返回的 header 的字段是有可能重复的,最常见的就是 Set-Cookie

服务端返回 header 如图:

如今 request 里的 success 给的 header 是个 Set,值只有第一个 Set-Cookie:

面对 Request 里的 Cookie 问题,官方也没有提供解决方案,

JS 写解析 header 还挺吃力,

加上现在这个没法返回完整的 header 表示…无力吐糟…

不知道官方是故意让我们解藕 Cookie,用不同的两套逻辑,还是疏漏???

1 回复

你好,request 返回的 header 是一个 key-value 的 Object,其中 key 是 field-name ,value 是 filed-value。根据 RFC2616(https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2) 的定义,如果同一个 filed-name 返回了多个 field-value,会以逗号分隔开来。小程序 request 接口的也是遵循这个标准的,而不是你描述的只有第一个值。

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one “field-name: field-value” pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

回到顶部