Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixed forwarded_for_address #767

Closed
wants to merge 1 commit into from

3 participants

@nichtich

IP can be in HTTP_X_FORWARDED_FOR instead of X_FORWARDED_FOR. By the way the 'address' should automatically use 'forwarded_for_address' if proxy_pass is set, should'nt it?

@xsawyerx
Owner

In what situation will it be HTTP_X_FORWARDED_FOR?

I believe the PSGI spec only speaks of X_FORWARDED_FOR.

@nichtich

The PSGI spec only speaks of HTTP_... headers, that "correspond to the client-supplied HTTP request headers" and the "key is obtained converting the HTTP header field name to upper case, replacing all occurrences of hyphens - with underscores and prepending HTTP, as in RFC 3875." It highly depends on your Deployment environment whether X_FORWARDED_FOR or HTTP_X_FORWARDED_FOR is set.

@doherty

Could you clarify how you would end up with the HTTP_ string not being prepended to the keys of the HTTP headers? I think the plain reading of the PSGI spec indicates that the HTTP headers will have HTTP_ prepended. While the XFF header isn't (typically) provided by the "final" or "real" client, it is nevertheless provided by the client from PSGI's point of view. As such, you should expect it to have the prefix, and look for it in the environment accordingly.

@doherty

And in response to the original suggestion to for address to DTRT... Dancer should either figure out the right value, or not promise that it is providing the client's IP.

@yanick yanick closed this pull request from a commit
@yanick yanick Merge branch 'pr/767' into devel
Fixes #767
0d6428f
@yanick yanick closed this in 0d6428f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2012
  1. @nichtich
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/Dancer/Request.pm
View
2  lib/Dancer/Request.pm
@@ -50,7 +50,7 @@ sub new {
# aliases
sub agent { $_[0]->user_agent }
sub remote_address { $_[0]->address }
-sub forwarded_for_address { $_[0]->env->{'X_FORWARDED_FOR'} }
+sub forwarded_for_address { $_[0]->env->{'X_FORWARDED_FOR'} || $_[0]->env->{'HTTP_X_FORWARDED_FOR'} }
sub address { $_[0]->env->{REMOTE_ADDR} }
sub host {
if (@_==2) {
Something went wrong with that request. Please try again.