Hi,
I'd like to make an akka-http based file server that returns requested
large binary files
(using chunking and ByteStrings), but haven't found any suitable examples
yet.
So something like this:
case class FileServer(interface: String, port: Int) {
implicit val system = ActorSystem()
import system.dispatcher
implicit val materializer = FlowMaterializer()
implicit val askTimeout: Timeout = 500.millis
IO(Http) ? Http.Bind(interface, port) foreach {
case Http.ServerBinding(localAddress, connectionStream) ⇒
Source(connectionStream).foreach({
case Http.IncomingConnection(remoteAddress, requestProducer,
responseConsumer) ⇒
Source(requestProducer).map(requestHandler).to(Sink(responseConsumer)).run()
})
}
val requestHandler: HttpRequest ⇒ HttpResponse = {
case HttpRequest(GET, _, _, _, _) ⇒
val filename = ??? // how to get file name from URI path or use id
attribute?
def output = scala.io.Source.fromFile(filename)
HttpResponse(
entity = HttpEntity.Chunked(ContentTypes.`application/octet-stream`,
Flow(???) // how to return the file contents in chunks of
ByteStrings?
)
case _: HttpRequest ⇒ HttpResponse(404, entity = "Unknown resource!")
}
}
Any suggestions on how to implement this? Any examples for the client side?
Thanks,
Allan
--
>>>>>>>>>> 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.