Return html from a play framework chain


I have a chain of two Play Framework applications. The first is the GatewayServer and the second the InformationServer. The first makes an web service call to the second and should return html to the calling browser - but there the html is only displayed as text. Here is my code:

  def information() : Action[AnyContent] = Action.async {
    val request: WSRequest = ws.url("http://localhost:9001/serverInformation/http/superProprietor/information")
    val requestWithTimeout = request.withRequestTimeout(10000.millis)
    requestWithTimeout.get().map{ response => Ok(response.body) }

What should I change to get the desired result as html in the browser?


response.body is a String, so Play is using the default Writeable[String] instance, which uses the content-type text/plain (ContentTypes.TEXT). If you want to treat it as text/html you can use:


In your case you could also do something like:


That would just forward the body and content-type from your response as-is.

If you want to forward the status and headers as well, you can look at the responses here: scala - How to forward a WSResponse without explicitly mapping the result - Stack Overflow (the one for 2.6 should work for later versions as well)