Search code examples
javascalahttpparsingrenderer

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 (i.e. does not depend on direct socket access and does not create / expect actual network connections).

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. 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).

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
  • Appache Http Components: seems to be geared towards usage with sockets, lower levels are accessible but it doesn't feel like intended use
  • others spray, netty not sure if they would work out any experience?

Any suggestions are welcome!

Update

Regarding Akka HTTP: I mean the onUpstreamFailure behavior, which is handled directly in the serverLayer blueprint. 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.

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

Solution

  • 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)
    • Netty provides EmbeddedChannels which allows to execute HTTP Parsers / Renderers / Decoders without binding to a socket. 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)