Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ivatar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oliver Falk
ivatar
Merge requests
!79
Fix middleware to do exactly what we want/need
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix middleware to do exactly what we want/need
devel
into
master
Overview
0
Commits
4
Pipelines
2
Changes
2
Merged
Oliver Falk
requested to merge
devel
into
master
6 years ago
Overview
0
Commits
4
Pipelines
2
Changes
2
Expand
0
0
Merge request reports
Compare
master
version 1
c1d6a751
6 years ago
master (base)
and
latest version
latest version
aeb0a529
4 commits,
6 years ago
version 1
c1d6a751
3 commits,
6 years ago
2 files
+
6
−
14
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
ivatar/middleware.py
+
5
−
13
Options
@@ -6,21 +6,13 @@ from django.utils.deprecation import MiddlewareMixin
class
MultipleProxyMiddleware
(
MiddlewareMixin
):
# pylint: disable=too-few-public-methods
"""
Middleware to rewrite proxy headers for deployments
multiple proxies
with
multiple proxies
"""
FORWARDED_FOR_FIELDS
=
[
'
HTTP_X_FORWARDED_FOR
'
,
'
HTTP_X_FORWARDED_HOST
'
,
'
HTTP_X_FORWARDED_SERVER
'
,
]
def
process_request
(
self
,
request
):
"""
Rewrites the proxy headers so that
only the most
recent proxy is used
.
Rewrites the proxy headers so that
forwarded server is
used if available
.
"""
for
field
in
self
.
FORWARDED_FOR_FIELDS
:
if
field
in
request
.
META
:
if
'
,
'
in
request
.
META
[
field
]:
parts
=
request
.
META
[
field
].
split
(
'
,
'
)
request
.
META
[
field
]
=
parts
[
-
1
].
strip
()
if
'
HTTP_X_FORWARDED_SERVER
'
in
request
.
META
:
request
.
META
[
'
HTTP_X_FORWARDED_HOST
'
]
=
request
.
META
[
'
HTTP_X_FORWARDED_SERVER
'
]
Loading