如何在Reslet上启用JSON响应实体的GZIP压缩? [英] How can I enable GZIP compression of the JSON response entity on Reslet?

查看:148
本文介绍了如何在Reslet上启用JSON响应实体的GZIP压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个Restlet应用程序正在运行,该应用程序可以接受JSON并返回JSON实体作为响应.

I have a Restlet application already working that accepts JSON and returns JSON entity as response.

我试图了解如何压缩响应中返回的JSON实体. 我没有找到任何明确的例子来实现它.

I'm trying to understand how I can compress the JSON entity that is returned in the response. I did not find any clear example on how to achieve it.

我认为我必须在路由器链上放置Encoder/EncoderService类,但是我真的不知道在哪里以及如何使用它们.

I think I have to put somewhere on the router chain the Encoder/EncoderService classes, but I really don't understand where and how to use them.

有人可以帮助我吗?

推荐答案

经过测试,我得到了答案.

After some testing, I got the answer.

像这样创建一个新的过滤器

Creating a new filter like this

Filter encoder = new Encoder(getContext(), false, true, new EncoderService(true));

在我自己的Application类的createInboundRoot()方法内部可以完成此操作,客户端请求已经包含所需的gzip标头.

inside the createInboundRoot() method of my own Application class did the trick, the client requests were already containing the gzip header needed.

这篇关于如何在Reslet上启用JSON响应实体的GZIP压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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