-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a way of configuring the SDK to extract IP headers.
- Loading branch information
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
from castle.configuration import configuration | ||
|
||
|
||
class ExtractorsIp(object): | ||
def __init__(self, request): | ||
self.request = request | ||
|
||
def call(self): | ||
ip_address = self.get_ip_from_headers() | ||
if ip_address: | ||
return ip_address | ||
|
||
if hasattr(self.request, 'ip'): | ||
return self.request.ip | ||
|
||
return self.request.environ.get('REMOTE_ADDR') | ||
|
||
def get_ip_from_headers(self): | ||
for header in configuration.ip_headers: | ||
value = self.request.environ.get(header) | ||
if value: | ||
return value | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters