title: Chunked response handling with spray example
body: <p>Documentation <a href="http://spray.io/documentation/spray-can/http-client/#chunked-responses" rel="noreferrer">states</a> that spray is able to handle chunked responses but I can't find any example to start with. There is my naive implementation:</p>
  
  <pre><code>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) =&gt;
        log.info("Success: " + a)
        system.shutdown()
  
      case Failure(error) =&gt;
        log.error(error, "Failure")
        system.shutdown()
    }
  
  }
  </code></pre>
  
  <p>I've set <code>response-chunk-aggregation-limit = 0</code>, nothing still happens.</p>
  
  <p>Can you provide me with example of reading chunked response?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I've rewritten my code as following:</p>
  
  <pre><code>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(_) =&gt;
          log.info("connected")
          sender ! HttpRequest(GET, "/output.cgi.xml")
        case Closed(handle, reason) =&gt;
          log.info("closed: " + reason)
          system.shutdown()
        case ChunkedResponseStart(res) =&gt;
          log.info("start: " + res)
        case MessageChunk(body, ext) =&gt;
          log.info("chunk: " + body)
        case ChunkedMessageEnd(ext, trailer) =&gt;
          log.info("end: " + ext)
        case m =&gt;
          log.info("received unknown message " + m)
          system.shutdown()
      }
    })
  
  }
  </code></pre>
  
  <p>And now I'm receiving <code>closed: ProtocolError(Aggregated response entity greater than configured limit of 1048576 bytes)</code> just after connection is established.</p>
  
  <p>My application.conf</p>
  
  <pre><code>spray.can {
    client {
      response-chunk-aggregation-limit = 0
    }
  }
  </code></pre>