Spray Interference Processing

The documentation indicates that the spray is capable of handling response responses, but I cannot find any example to get started. My naive implementation:

object Main extends App { implicit val system = ActorSystem() import system.dispatcher val log = Logging(system, getClass) val ioBridge = IOExtension(system).ioBridge() val httpClient = system.actorOf(Props(new HttpClient(ioBridge))) val conduit = system.actorOf( props = Props(new HttpConduit(httpClient, "localhost", 3000)), name = "http-conduit" ) val pipeline = HttpConduit.sendReceive(conduit) val response = pipeline( HttpRequest( method = GET, uri = "/output.cgi.xml" ) ) response onComplete { case Success(a) => log.info("Success: " + a) system.shutdown() case Failure(error) => log.error(error, "Failure") system.shutdown() } } 

I set response-chunk-aggregation-limit = 0 , nothing happens.

Can you provide me an example of reading a fragmented response?

Update

I rewrote my code as follows:

 object Main extends App { implicit val system = ActorSystem() import system.dispatcher val log = Logging(system, getClass) val ioBridge = IOExtension(system).ioBridge() val httpClient = system.actorOf(Props(new HttpClient(ioBridge))) actor(new Act { httpClient ! Connect(new InetSocketAddress("localhost", 3000)) become { case Connected(_) => log.info("connected") sender ! HttpRequest(GET, "/output.cgi.xml") case Closed(handle, reason) => log.info("closed: " + reason) system.shutdown() case ChunkedResponseStart(res) => log.info("start: " + res) case MessageChunk(body, ext) => log.info("chunk: " + body) case ChunkedMessageEnd(ext, trailer) => log.info("end: " + ext) case m => log.info("received unknown message " + m) system.shutdown() } }) } 

And now I get closed: ProtocolError(Aggregated response entity greater than configured limit of 1048576 bytes) right after the connection is established.

My application.conf

 spray.can { client { response-chunk-aggregation-limit = 0 } } 
+7
source share
1 answer

As you noticed, HttpConduit only works on aggregated responses. You have to fall to the spray layer to process individual pieces.

Unfortunately, we do not currently have an example showing how you will do this. Roughly, it works like this (in M7):

  • Set response-chunk-aggregation-limit = 0
  • Send Connect to the httpClient Client and Wait for Connected
  • Send HttpRequest to the sender of the Connected message
  • Handle ChunkedResponseStart , MessageChunk and ChunkedResponseEnd .

See http://spray.io/documentation/spray-can/http-client/#chunked-responses for details

Unlike using HttpConduit , this means that you need to manage your connections yourself (if you use HttpConduit). The last night hours have become easier because the new HttpClient automatically supports connection pools, etc. If you need, you can also get more information on the mailing list.

+9
source

All Articles