如今,在将一位HTTP主体发送到浏览器之前,HTTP标头都需要发送。
这对于诸如React 18流的新技术尤其有问题,其中某些标头(例如缓存标头和 103早期提示
)只能在HTTP流的末尾确定。理想情况下,这些后期标头将在结束流之前将其发送到浏览器。
Spec工作组或浏览器供应商是否有能力在HTTP主体期间/之后发送标头?
进行研究之后,似乎没有关于此事的规格工作,但是我想知道是否有浏览器供应商正在为此工作吗? (一些浏览器的人在stackoverflow上处于活动状态。)
上下文:我是和 react-streaming 。
Today, HTTP headers all need to be sent before a single bit of HTTP body is sent to the browser.
This is especially problematic with new technologies such as React 18 Streaming where certain headers, such as caching headers and 103 Early Hints
, can be determined with certainty only at the end of the HTTP stream. Ideally these late headers would be sent to the browser just before ending the stream.
Are there efforts from spec working groups or browser vendors to enable headers to be sent during/after the HTTP body?
After doing research, it seems that there is no spec work about this, but I wonder if there is a browser vendor working on this? (Some browser folks are active here on StackOverflow.)
Context: I'm the author of vite-plugin-ssr and react-streaming.
发布评论
评论(1)
有针对截面编码的拖车字段的规范(http 1.1,)。
HTTP2 SPEC(不支持块编码)直接允许遵循包含http车身的数据框架 https://datatracker.ietf.org/doc/html/rfc7540#section-8.1 。
由于大多数HTTP库都试图抽象基础协议中的差异,因此库支持可能会有所不同。在JavaScript中,您将有兴趣在跨浏览器标准fetch API中启用尾随标题。 MDN文档建议,支持
预告片
字段响应对象: https://developer.mozilla.org/en-us/docs/web/api/response 。There is a specification for Trailer fields for use with Chunked Encoding (Http 1.1, https://httpwg.org/specs/rfc7230.html#header.trailer).
The HTTP2 spec (which does not support Chunked Encoding) directly allows for a headers frame following the Data frames that contain the http body https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.
Library support may vary as most http libraries attempt to abstract away the differences in the underlying protocols. In Javascript you will be interested in enabling trailing headers in the cross-browser standard fetch API. The MDN docs suggest that support is coming with reference to a
trailers
field on theResponse
object: https://developer.mozilla.org/en-US/docs/Web/API/Response.