简体   繁体   English

适用于Java / Scala的HTTP解析器/渲染器库

[英]HTTP parser/renderer library for Java/Scala

I'm searching for an asynchronous HTTP parsing/rendering library that can be hooked up to a stream of bytes (ie does not depend on direct socket access and does not create / expect actual network connections). 我正在寻找一个可以连接到字节流的异步HTTP解析/渲染库(即,不依赖于直接套接字访问,也不创建/期望实际的网络连接)。

Basically given a stream of bytes I want to be able to parse a HTTP request from it, potentially manipulate something and render it to a byte string. 基本上给定了字节流,我希望能够从中解析一个HTTP请求,潜在地操纵某些内容并将其呈现为字节字符串。 Both for requests and responses. 无论是请求还是响应。 Ideally for strict and chunked requests. 理想地用于严格和分块的请求。

In principal a manipulating Http proxy that works on input streams, java streams, reactive streams or something similar (client & server). 原则上讲,可在输入流,java流,响应流或类似内容(客户端和服务器)上使用的Http代理。

something like this: 像这样的东西:

stream of bytes <-> HttpLib <-> customCode <-> HttpLib <-> stream of bytes

so far I looked at 到目前为止,我看着

  • Akka Http: close to what I need but error behavior is hard coded Akka Http:接近我所需要的,但是错误行为是硬编码的
  • Appache Http Components: seems to be geared towards usage with sockets, lower levels are accessible but it doesn't feel like intended use Appache Http组件:似乎适合与套接字一起使用,可以访问较低的级别,但感觉不像预期的用途
  • others spray, netty not sure if they would work out any experience? 其他人喷了喷雾,Netty不确定他们是否会有任何经验?

Any suggestions are welcome! 欢迎任何建议!

Update 更新资料

Regarding Akka HTTP: I mean the onUpstreamFailure behavior, which is handled directly in the serverLayer blueprint. 关于Akka HTTP:我的意思是onUpstreamFailure行为,该行为直接在serverLayer蓝图中处理。 I guess that's the most efficient / convenient default but how could streams stages after the serverLayer react to such errors (optionally) propagating the error would be more flexible. 我猜这是最有效/最方便的默认值,但是在serverLayer对此类错误做出反应(可选)之后,如何传播阶段会更灵活。

-> Bytes -> serverLayer -> customCode
                 |
  <- (error response)

In case somebody stumbles across the question 万一有人偶然发现了这个问题

  • Akka HTTP would be a great choice in general just doens't work that nice for us (see question) 一般而言,Akka HTTP将是一个不错的选择,只是对我们没有用(请参阅问题)
  • Netty provides EmbeddedChannels which allows to execute HTTP Parsers / Renderers / Decoders without binding to a socket. Netty提供了EmbeddedChannels,该通道允许执行HTTP解析器/渲染器/解码器而无需绑定到套接字。 I think this is mainly intended for testing but its not in .test packages and can also be used for implementation of higher level codecs (Netty 3.x documentation) 我认为这主要用于测试,但不用于.test软件包,也可以用于实现更高级别的编解码器(Netty 3.x文档)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM