Permalink
Browse files

Hacked in Request(Header).remoteAddress to the Scala API

  • Loading branch information...
teozkr authored and Olivier Refalo committed Mar 17, 2012
1 parent aaa51ef commit 78dbc7894c1f73557ea7b41bd48c468e4f3ae871
@@ -29,8 +29,9 @@ case class FakeHeaders(data: Map[String, Seq[String]] = Map.empty) extends Heade
* @param uri The request uri.
* @param headers The request HTTP headers.
* @param body The request body.
+ * @param remoteAddress The client IP.
*/
-case class FakeRequest[A](method: String, uri: String, headers: FakeHeaders, body: A) extends Request[A] {
+case class FakeRequest[A](method: String, uri: String, headers: FakeHeaders, body: A, remoteAddress: String = "127.0.0.1") extends Request[A] {
/**
* The request path.
@@ -37,6 +37,11 @@ package play.api.mvc {
*/
def headers: Headers
+ /**
+ * The client IP address.
+ */
+ def remoteAddress: String
+
/**
* The HTTP host (domain, optionally port)
*/
@@ -119,6 +124,7 @@ package play.api.mvc {
def method = self.method
def queryString = self.queryString
def headers = self.headers
+ def remoteAddress = self.remoteAddress
lazy val body = f(self.body)
}
@@ -134,6 +140,7 @@ package play.api.mvc {
def path = request.path
def uri = request.uri
def method = request.method
+ def remoteAddress = request.remoteAddress
}
/**
@@ -48,6 +48,10 @@ private[server] class PlayDefaultUpstreamHandler(server: Server, allChannels: De
val nettyUri = new QueryStringDecoder(nettyHttpRequest.getUri)
val parameters = Map.empty[String, Seq[String]] ++ nettyUri.getParameters.asScala.mapValues(_.asScala)
+ val rRemoteAddress = e.getRemoteAddress match {
+ case ra: java.net.InetSocketAddress => ra.getAddress.getHostAddress
+ }
+
val rHeaders = getHeaders(nettyHttpRequest)
val rCookies = getCookies(nettyHttpRequest)
@@ -61,6 +65,7 @@ private[server] class PlayDefaultUpstreamHandler(server: Server, allChannels: De
def method = nettyHttpRequest.getMethod.getName
def queryString = parameters
def headers = rHeaders
+ def remoteAddress = rRemoteAddress
def username = None
}
@@ -289,6 +294,7 @@ private[server] class PlayDefaultUpstreamHandler(server: Server, allChannels: De
def queryString = parameters
def headers = rHeaders
def username = None
+ def remoteAddress = rRemoteAddress
val body = b
})
}

0 comments on commit 78dbc78

Please sign in to comment.