Created
February 24, 2013 19:29
-
-
Save langley/5025178 to your computer and use it in GitHub Desktop.
A universal "Web Proxy Service" action for Play 2.1 Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to your conf/routes file | |
# Universal Proxy | |
GET /proxyGet/*urlToProxy controllers.Application.proxyGet(urlToProxy) | |
# Add this to a Controller class, e.g. Application | |
import play.api.libs.ws.WS | |
import play.api.libs.concurrent.Execution.Implicits._ | |
def proxyGet(urlToProxy: String) = Action { | |
Async { | |
WS.url("http://" + urlToProxy).get().map { response => | |
val contentType = response.header("Content-Type").getOrElse("text/plain") | |
Ok(response.body).as(contentType) | |
} | |
} | |
} |
this is cool - I need to proxy POST as well. Can you point me to any examples?
Hey I am not sure if anyone is still looking but I based a class on this and it has all the requests https://github.com/gdh56/scalaPlayProxy/blob/master/proxy.scala
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this was for Play 2.1