gpt4 book ai didi

javascript - HTTP2:是否可以在流上发送后续或附加的 HEADER block ?

转载 作者:行者123 更新时间:2023-12-02 20:59:53 24 4
gpt4 key购买 nike

Node提供了这个方法:

http2stream.additionalHeaders(headers)

哪个Sends an additional informational HEADERS frame to the connected HTTP/2 peer.

但是 Node 代码库包含以下注释:

// Sends a block of informational headers. In theory, the HTTP/2 spec
// allows sending a HEADER block at any time during a streams lifecycle,
// but the HTTP request/response semantics defined in HTTP/2 places limits
// such that HEADERS may only be sent *before* or *after* DATA frames.
// If the block of headers being sent includes a status code, it MUST be
// a 1xx informational code and it MUST be sent before the request/response
// headers are sent, or an error will be thrown.

是否可以在流上发送后续或附加的 HEADER block ?

例如伪代码:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)
stream.write(DATA)
stream.end(DATA)

还有:

  • 如果可能请提供一些演示代码;或

  • 如果不是的话 additionalHeaders 的意义何在?函数,如 response事件返回标题 headers 的意义是什么?事件?

最佳答案

根据评论,以下内容不是有效的 HTTP/2:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)
stream.write(DATA)
stream.end(DATA)

但以下是:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)

这允许您发送 trailing header ,通常用于动态生成的内容的校验和或其他完整性检查,这些内容无法提前知道在第一个 headers 请求中发送(最好提前发送 headers,而不是之后发送 headers)。

关于javascript - HTTP2:是否可以在流上发送后续或附加的 HEADER block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61380526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com