Permalink
Browse files

Converters change

  • Loading branch information...
1 parent 1217ad9 commit c45e9f50fa16c201915670d828c6d93ce7bb0a18 @Kashomon Kashomon committed Nov 12, 2010
@@ -1,3 +1,3 @@
#Project properties
-#Fri Oct 22 08:50:15 MDT 2010
+#Thu Nov 11 17:25:46 MST 2010
plugin.uptodate=true
@@ -64,13 +64,10 @@ object Converters {
val headers = buildHeaders(request.getHeaders())
val nettyContent = request.getContent()
val content = if (nettyContent.readable()) Some(fromChannelBuffer(nettyContent, transcoder)) else None
- val remoteHost = headers.find(v => v._1.toLowerCase() == "x-forwarded-for").map(_._2) match {
- case Some(x) => HttpIps.parseSingleIp(x).map(_.ip)
- case None => remoteAddres match {
- case x: InetSocketAddress => Some(x.getAddress())
- case _ => None
- }
- }
+
+ val xforwarded: Option[HttpHeaders.`X-Forwarded-For`] = (for (`X-Forwarded-For`(value) <- headers) yield `X-Forwarded-For`(value: _*)).headOption
+
+ val remoteHost = xforwarded.flatMap(_.ips.headOption.map(_.ip)).orElse(Some(remoteAddres).collect { case x: InetSocketAddress => x.getAddress })
HttpRequest(fromNettyMethod(request.getMethod), request.getUri, params, headers, content, remoteHost, fromNettyVersion(request.getProtocolVersion()))
}
@@ -58,7 +58,7 @@ class ConvertersSpec extends Specification {
val nettyRequest = new DefaultHttpRequest(NettyHttpVersion.HTTP_1_0, NettyHttpMethod.GET, "http://foo/bar?param1=value1")
nettyRequest.setContent(ChannelBuffers.wrappedBuffer("12".getBytes))
nettyRequest.setHeader("retry-after", "1")
- nettyRequest.setHeader("x-forwarded-for", "111.11.11.1, 121.21.2.2")
+ nettyRequest.setHeader("X-Forwarded-For", "111.11.11.1, 121.21.2.2")
val address = new InetSocketAddress("127.0.0.0", 8080)
val forwardedAddress = new InetSocketAddress("111.11.11.1", 8080)
@@ -67,7 +67,7 @@ class ConvertersSpec extends Specification {
request.method mustEqual(HttpMethods.GET)
request.uri mustEqual("http://foo/bar?param1=value1")
request.parameters mustEqual(Map('param1 -> "value1", 'pathParam1 -> "value"))
- request.headers mustEqual(Map("retry-after" -> "1", "x-forwarded-for" -> "111.11.11.1, 121.21.2.2"))
+ request.headers mustEqual(Map("retry-after" -> "1", "X-Forwarded-For" -> "111.11.11.1, 121.21.2.2"))
request.content mustEqual(Some("12"))
request.version mustEqual(`HTTP/1.0`)
request.remoteHost mustEqual(Some(forwardedAddress.getAddress()))

0 comments on commit c45e9f5

Please sign in to comment.