scala - How to parse a byte stream into `HttpRequest` objects with akka-http? -
from documentation: "there's no public api provided parse (or render to) strings or byte arrays". how can use private api parse network stream httprequest
objects?
also, should input-byte-stream be?
- unordered packets (ethernet , up)
- unordered tcp packets
- ordered tcp payloads (http raw requests, in order) (this guess)
note:
- my byte stream contain http requests, not responses
- i'm getting byte stream pcap file, not live http client. (which why i'm asking how need parse before sending akka-http)
- if think it's bad idea, please explain, big too.
- i suspect involves using http().serverlayer. i'm not sure.
link: related question in akka google group
thanks!
this possible, fiddly. have done this, can't post full code here, it's private.
the relevant akka code in httprequestparser
most of code package-private, you'll need write helper class of own in akka.http
package access it.
the code this:
package akka.http /** * class gives access akka's [[akka.http.impl.engine.parsing.httprequestparser]]. * * in akka package, of akka's parsing code package-private. * * @see [[akka.http.impl.engine.server.httpserverblueprint]] */ class httprequestparserhelper()( implicit system: actorsystem, materializer: materializer) { def unmarshalrequest(wireformat: array[byte]): httprequest = { val input = bytestring(wireformat) val requestfuture = source.single(input) .via(requestparsingflow()) .runwith(streams.getsingleelement) .transform(identity, e => new ioexception("error unmarshalling request", e)) await.result(requestfuture, 10.seconds) } /** * akka flow parses incoming bytestrings , emits httprequests. * * code copied [[akka.http.impl.engine.server.httpserverblueprint]] */ private def requestparsingflow(): flow[bytestring, httprequest, any] = { ... } }
fill in requestparsingflow
akka source code, removing bits aren't applicable until compiles.
the input data needs tcp stream data, i.e. option (3) question.
good luck!
Comments
Post a Comment