Java HTTP Client是否处理压缩 [英] Does Java HTTP Client handle compression

查看:181
本文介绍了Java HTTP Client是否处理压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在新的Java HTTP Client中找到有关压缩处理的任何内容,但均失败了.是否有内置的配置可以处理例如gzipdeflate压缩?

我希望有一个BodyHandler,例如像这样的东西:

HttpResponse.BodyHandlers.ofGzipped(HttpResponse.BodyHandlers.ofString())

但是我没看到.我也没有在HttpClient中看到任何配置.我在找错地方了吗?还是故意不执行并推迟支持图书馆?

解决方案

否,默认情况下不处理gzip/deflate压缩.如果需要,您必须在应用程序代码中实现它-例如通过提供自定义的BodySubscriber来处理它.或者-您可能想看看那里的一些反应流库是否提供了这样的功能,在这种情况下,您可以使用BodyHandlers.fromSubscriber​(Flow.Subscriber<? super List<ByteBuffer>> subscriber)BodyHandlers.ofPublisher()方法之一将其引入./p>

I tried to find any mention of handling of compression in new Java HTTP Client but failed. Is there a built-in configuration to handle for e.g. gzip or deflate compression?

I would expect to have a BodyHandler for e.g. something like this:

HttpResponse.BodyHandlers.ofGzipped(HttpResponse.BodyHandlers.ofString())

but I don't see any. I don't see any configuration in HttpClient either. Am I looking in the wrong place or was this intentionally not implemented and deferred to support libraries?

解决方案

No, gzip/deflate compression are not handled by default. You would have to implement that in your application code if you need it - e.g. by providing a customized BodySubscriber to handle it. Alternatively - you may want to have a look at whether some of the reactive stream libraries out there offer such a feature, in which case you might be able to pipe that in by using one of the BodyHandlers.fromSubscriber​(Flow.Subscriber<? super List<ByteBuffer>> subscriber) or BodyHandlers.ofPublisher() methods.

这篇关于Java HTTP Client是否处理压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆