netty是http解析器可重用的,如何使用? [英] netty is http parser re-usable and how?

查看:175
本文介绍了netty是http解析器可重用的,如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要可重用的异步http解析代码. netty是否可能仅包含用于解析部分的api? (我一直认为解析器应该是独立且可重用的,并且不与框架绑定,因此我希望netty也可以重用.)

I need re-usable async http parsing code. Does netty perhaps contain some api for just the parsing portion? (I always have a belief that parsers should be separate and re-usable and not tied to the framework so I hope netty's is reusable as well).

即.像这样输入字节会很棒,如果返回,则返回null 没有足够的字节数

ie. It would be great to feed in bytes like so and it returns null if there is not yet enough bytes

private byte[] previousData;

byte[] data = incomingMergedWithPrevious(previousData);
HttpResponse resp = httpResponseParser.parse(data);
if(resp == null) {
    return; //we do not have full data to parse yet
}

//otherwise fire the response to someone else.

或者也许我可以以其他方式重用代码.我所知道的是我得到了 字节并不总是具有所有http标头,因为它是 庇护的东西.有什么办法解析东西吗?

OR maybe I could re-use the code a different way. All I know is I get bytes that don't always have all the http headers yet since it is asynch stuff. Any way to parse stuff?

注意:另外,我想进行分块,所以我不确定每次都应返回HttpResponse,但可能不是一个列表,其中一个子类是HttpHeaders,另一个子类是HttpChunk.

NOTE: Also, I want to do chunking so I am not sure it should return HttpResponse every time but maybe an List where one subclass is HttpHeaders and another is HttpChunk.

谢谢, 院长

推荐答案

您可以使用

You can use the DecoderEmbedder probably in conjunction with HttpMessageDecoder. There's an example on the DecoderEmbedder page. It sounds like you want to use the pollAll method. You'll need to check the type of each returned object if you want to process HttpResponse and HttpChunk messages differently.

这篇关于netty是http解析器可重用的,如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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