问题描述
我需要可重用的异步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 ifthere 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 getbytes that don't always have all the http headers yet since it isasynch 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.
谢谢,院长
推荐答案
您可以使用 DecoderEmbedder 可能与 HttpMessageDecoder . DecoderEmbedder页面上有一个示例.听起来您想使用pollAll方法.如果要以不同方式处理HttpResponse和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解析器可重用的,如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!