playframework/Play20 — pull request #233 by julienrf (2012-04-12 20:13:42+00:00)
Title: Remote address support

I started with the code of this [pull request](https://github.com/playframework/Play20/pull/200) and tried to add support for `X-Forwarded-For` header: if there is an `X-Forwarded-For` header and either the client IP is `127.0.0.1` or a configuration key `trustxforwarded` is defined and equal to `true`, the value of the header is used. Otherwise, the remote address provided by Netty is used.

Some things to mention:

* I didn’t tested behind a reverse proxy
* I wasn’t sure of the way to retrieve the `Application`: I could have used `play.api.Play.current` but wasn’t sure it’s the better way to retrieve it from the netty handler, so I went through `server.applicationProvider`
* I didn’t create an entry for the `X-Forwarded-For` header name in `play.api.http.HeaderNames` since that’s not a real “standard” header, but maybe I was wrong
* Very often, in the existing code, `def`s are used where `val`s could be used to improve performance (unless I’m wrong?). Is there a reason to have chosen `def`s? In doubt I let the existing code as is.