Fix resolving X-Forwarded-For header

This fixes X-Forwarded-For resolving (HTTP_ prefix). This is fixed
on develop branch differently. However current behaviour renders
invalid results and IMHO this patch should merged and released
as 2.3.NEXT

The patch is backward compatible (prefers X_FORWARDED_FOR to HTTP_X_FORWARDED_FOR). Tests are included.