aboutsummaryrefslogtreecommitdiff
path: root/akka-http-handler
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-15 10:58:24 +0200
committeradamw <adam@warski.org>2017-07-15 10:58:24 +0200
commitbc685df2cd50814b45e669f4f602732887c2879c (patch)
tree4df984768865b86b48fbaae7c21f22fd0c3ea079 /akka-http-handler
parentfdc9b3f9420165cc65c8dd9fe20057a4a12e69c6 (diff)
downloadsttp-bc685df2cd50814b45e669f4f602732887c2879c.tar.gz
sttp-bc685df2cd50814b45e669f4f602732887c2879c.tar.bz2
sttp-bc685df2cd50814b45e669f4f602732887c2879c.zip
Headers & errors support
Diffstat (limited to 'akka-http-handler')
-rw-r--r--akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala12
1 files changed, 11 insertions, 1 deletions
diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
index fc2d632..9125ca3 100644
--- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
+++ b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
@@ -14,6 +14,7 @@ import com.softwaremill.sttp.model._
import scala.concurrent.Future
import scala.util.{Failure, Success, Try}
+import scala.collection.immutable.Seq
class AkkaHttpSttpHandler(actorSystem: ActorSystem)
extends SttpHandler[Future, Source[ByteString, Any]] {
@@ -32,7 +33,8 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem)
.flatMap(Http().singleRequest(_))
.flatMap { hr =>
val code = hr.status.intValue()
- bodyFromAkka(responseAs, hr).map(Response(code, _))
+ bodyFromAkka(responseAs, hr).map(
+ Response(_, code, headersFromAkka(hr)))
}
}
@@ -72,6 +74,14 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem)
}
}
+ private def headersFromAkka(hr: HttpResponse): Seq[(String, String)] = {
+ val ch = ContentTypeHeader -> hr.entity.contentType.toString()
+ val cl =
+ hr.entity.contentLengthOption.map(ContentLengthHeader -> _.toString)
+ val other = hr.headers.map(h => (h.name, h.value))
+ ch :: (cl.toList ++ other)
+ }
+
private def requestToAkka(r: Request): Future[HttpRequest] = {
val ar = HttpRequest(uri = r.uri.toString, method = methodToAkka(r.method))
val parsed =