HTTP / 2客户端

系统教程 行业动态 更新时间:2024-06-14 17:03:54
HTTP / 2客户端 - 将响应关联到请求 - 可以依赖流ID吗?(HTTP/2 client - associate response to request - can rely on stream id?)

我正在尝试使用netty来实现HTTP / 2客户端。 在这个例子中 (第93行),他们手动递增streamId并将其放入地图。 当响应到来时,它们会查找HttpConversionUtil.ExtensionHeaderNames.STREAM_ID标头参数,从而将响应与请求相关联。

我不喜欢自己增加streamId的想法。 我可以以某种方式获得id writeAndFlush将用于writeAndFlush请求吗?

此外,创建新流需要很多资源吗? 或者它只是一个标识符?

I'm trying to use netty to implement HTTP/2 client. In this example (line 93) they manually increment streamId and put it to the map. When response comes they look for HttpConversionUtil.ExtensionHeaderNames.STREAM_ID header parameter and thus associate the response with the request.

I don't like the idea of increasing streamId by myself. Can I somehow get the id netty's going to use to writeAndFlush the request?

Also, does it take much resources to create a new stream? Or is it just an identifier?

最满意答案

我很确定,此时你无法获得streamId生成和使用的streamId 。 另外,我不喜欢自己增加streamId的想法,但看起来可以使用当前的API来做到这一点。

我检查了Netty的来源并找到了下面的东西:

HttpToHttp2ConnectionHandler用于写入请求。 它有私有方法getStreamId ,它在write方法中用于获取currentStreamId值。 但我们没有任何访问此变量的权限。 getStreamId方法使用另一个名为incrementAndGetNextStreamId的方法。 所以,再次,我们只能增加并获得新的streamId值,但无法获得当前的值。

这两个类都标有@UnstableApi注释,因此将来这种行为可能会发生变化。

这是一些相关的链接:

从Netty存储库稍微更新了HTTP 2客户端示例 。 HTTP / 2 Java客户端示例 。 为什么netty http2服务器总是使用奇数来表示streamId 。

I'm pretty sure, at this moment you can't get streamId generated and used by Netty. Also, I don't like the idea of increasing streamId by myself too, but looks like it's okay to do this with current API.

I've checked Netty sources and found next things:

HttpToHttp2ConnectionHandler is used for writing requests. It has private method getStreamId which is used in write method for getting value of currentStreamId. But we doesn't have any access to this variable. getStreamId method uses another method called incrementAndGetNextStreamId. So, again, we can only increment and get new streamId value but can't get the current one.

Both of these classes marked with annotation @UnstableApi, so maybe this behavior will be change in the future.

Here's some related links:

A little bit updated HTTP 2 client example from Netty repository. HTTP/2 Java Client Examples. Why netty http2 server always use odd number for streamId.

更多推荐

本文发布于:2023-04-24 14:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c0da029e59e32d673db3fd21e9b8ff34.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!