Reputation: 1450
For akka routing we use complete as follows. complete(HttpResponse)
Does this complete function accept only HttpResponse from akka.scalads.HttpResponse or even org.apache.http.HttpResponse. If it does'nt accept, can someone explain why?
Upvotes: 0
Views: 52
Reputation: 17973
complete Parameter Types
From the documentation you can see that complete
accepts many different parameter types, including akka's HttpResponse
:
def complete[T :ToResponseMarshaller](value: T): StandardRoute
def complete(response: HttpResponse): StandardRoute
def complete(status: StatusCode): StandardRoute
def complete[T :Marshaller](status: StatusCode, value: T): StandardRoute
def complete[T :Marshaller](status: Int, value: T): StandardRoute
def complete[T :Marshaller](status: StatusCode, headers: Seq[HttpHeader], value: T): StandardRoute
def complete[T :Marshaller](status: Int, headers: Seq[HttpHeader], value: T): StandardRoute
Apache/Akka Response
Complete does not, however, accept apache response types.
Most of the HttpResponse
member variables are easy enough to match against a corresponding apache variable with one big exception: the ResponseEntity
is an akka-stream Source[ByteString, Any]
. The apache HttpEntity
uses an InputStream
to represent the data which is not akka/stream aware, therefore a direct translation is not possible without a pre-existing akka ActorSystem
.
It is possible to write your own implicit conversion function from apache http response to akka http response which would allow you to pass apache responses to complete:
import akka.http.scaladsl.model.{HttpResponse => AkkaResponse}
import org.apache.http.{HttpResponse => ApacheResponse}
implicit def apacheToAkka(apacheResponse : ApacheResponse) : AkkaResponse = ???
val apacheResponse : ApacheResponse = ???
complete(apacheResponse)
Upvotes: 1