I am trying to created a chunked response from a series of files on the
file system. I am using the Test Server code as the basis.
Here is my sample code:
val requestHandler: HttpRequest ⇒ HttpResponse = {
case HttpRequest(GET, Uri.Path("/"), _, _, _) ⇒
val dir = "/test-data/"
println(s"\r\n handling request")
val s = Source(files.listFiles().filter(_.getName().endsWith(".txt")).
toIterator) map { file =>
println(s"\r\n reading file ${file.getName}")
java.nio.file.Files.readAllBytes(Paths.get(file.getAbsolutePath))
} map { byteArray =>
println(s"\r\n getting bytes ${byteArray.length}")
new GzipCompressor().compress(ByteString(byteArray))
}
HttpResponse(entity = HttpEntity.Chunked.fromData(MediaTypes.
`application/x-gzip`, s))
case _: HttpRequest ⇒ HttpResponse(404, entity = "Unknown resource!")
}
streamingServer foreach { case Http.ServerBinding(localAddress,
connectionStream) =>
Source(connectionStream) foreach { case Http.IncomingConnection(
remoteAddress, requestProducer, responseConsumer) =>
println(s"\r\n Accepted new connection from $remoteAddress")
Source(requestProducer).map(requestHandler).to(Sink(responseConsumer
)).run()
}
}
When I run this, I get a gz file in my browser, but I am not getting any of
the data.
Do I need to specify that this is a gzip stream or do something else so all
the bytes get down?
Here is the response header I am seeing:
1. Content-Type:
application/x-gzip
2. Date:
Wed, 26 Nov 2014 22:26:04 GMT
3. Server:
akka-http/2.3.7
4. Transfer-Encoding:
chunked
5.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.