Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
I
ipv6-dot-work
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ungleich-public
ipv6-dot-work
Commits
4e460726
Commit
4e460726
authored
Nov 29, 2018
by
Aatish Neupane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use x-real-ip headers
parent
8594e604
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
ipv6work/ipv6middleware.py
ipv6work/ipv6middleware.py
+10
-6
No files found.
ipv6work/ipv6middleware.py
View file @
4e460726
...
...
@@ -24,12 +24,16 @@ def block_ipv4(get_response):
return
get_response
(
request
)
path
=
request
.
path_info
.
lstrip
(
'/'
)
x_forwarded_for
=
request
.
META
.
get
(
'HTTP_X_FORWARDED_FOR'
)
if
x_forwarded_for
:
client_ip
=
x_forwarded_for
else
:
client_ip
=
request
.
META
.
get
(
'REMOTE_ADDR'
)
print
(
is_ipv6_exempt
(
path
),
is_valid_ipv6
(
client_ip
))
real_ip_headers
=
[
'HTTP_X_REAL_IP'
,
'REMOTE_ADDR'
,
'HTTP_X_FORWARDED_FOR'
]
client_ip
=
None
for
header
in
real_ip_headers
:
client_ip
=
request
.
META
.
get
(
header
)
if
client_ip
:
break
if
is_valid_ipv6
(
client_ip
)
or
is_ipv6_exempt
(
path
):
return
get_response
(
request
)
else
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment