rack/rack — pull request #598 by jasonbosco (2013-08-30 19:09:39+00:00)
Title: Use the first IP address in HTTP_X_FORWARDED_FOR as the originating IP

According to the [W3C guidelines](http://www.w3.org/TR/2009/WD-ct-guidelines-20091006/#sec-additional-headers) for the X-Forwarded-For HTTP header:

> proxies should add the IP address of the initiator of the request to the _**end**_ of a comma separated list in an X-Forwarded-For HTTP header field

So as a request goes through multiple proxies, the IP addresses of the proxies get appended to the **end** of the list in X-Forwarded-For. So the first IP address in this list is the originating client IP.

Currently, Rack::Request#ip returns the **last** IP address in the forwarded_ips list which is actually the IP address of the last proxy. This pull request fixes this issue by returning the first IP address in the list.