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?

  1. unordered packets (ethernet , up)
  2. unordered tcp packets
  3. ordered tcp payloads (http raw requests, in order) (this guess)

note:

  1. my byte stream contain http requests, not responses
  2. i'm getting byte stream pcap file, not live http client. (which why i'm asking how need parse before sending akka-http)
  3. if think it's bad idea, please explain, big too.
  4. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -