Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keycloak-proxy
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
Service Desk
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
Janne Mareike Koschinski
keycloak-proxy
Commits
e92c9b27
Unverified
Commit
e92c9b27
authored
7 years ago
by
Rohith Jayawardene
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Websocket Headers (#311)
- fixing up the headers for websockets
parent
1f5005e6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
forwarding.go
+14
-14
14 additions, 14 deletions
forwarding.go
with
14 additions
and
14 deletions
forwarding.go
+
14
−
14
View file @
e92c9b27
...
...
@@ -30,7 +30,7 @@ func (r *oauthProxy) proxyMiddleware(next http.Handler) http.Handler {
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
next
.
ServeHTTP
(
w
,
req
)
// step: retrieve the request scope
//
@
step: retrieve the request scope
scope
:=
req
.
Context
()
.
Value
(
contextScopeName
)
if
scope
!=
nil
{
sc
:=
scope
.
(
*
RequestScope
)
...
...
@@ -39,23 +39,12 @@ func (r *oauthProxy) proxyMiddleware(next http.Handler) http.Handler {
}
}
if
isUpgradedConnection
(
req
)
{
r
.
log
.
Debug
(
"upgrading the connnection"
,
zap
.
String
(
"client_ip"
,
req
.
RemoteAddr
))
if
err
:=
tryUpdateConnection
(
req
,
w
,
r
.
endpoint
);
err
!=
nil
{
r
.
log
.
Error
(
"failed to upgrade connection"
,
zap
.
Error
(
err
))
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
return
}
// add any custom headers to the request
// @step: add any custom headers to the request
for
k
,
v
:=
range
r
.
config
.
Headers
{
req
.
Header
.
Set
(
k
,
v
)
}
// By default goproxy only provides a forwarding proxy, thus all requests have to be absolute
// and we must update the host headers
// @note: by default goproxy only provides a forwarding proxy, thus all requests have to be absolute and we must update the host headers
req
.
URL
.
Host
=
r
.
endpoint
.
Host
req
.
URL
.
Scheme
=
r
.
endpoint
.
Scheme
if
v
:=
req
.
Header
.
Get
(
"Host"
);
v
!=
""
{
...
...
@@ -65,10 +54,21 @@ func (r *oauthProxy) proxyMiddleware(next http.Handler) http.Handler {
req
.
Host
=
r
.
endpoint
.
Host
}
// @step: add the proxy forwarding headers
req
.
Header
.
Add
(
"X-Forwarded-For"
,
realIP
(
req
))
req
.
Header
.
Set
(
"X-Forwarded-Host"
,
req
.
URL
.
Host
)
req
.
Header
.
Set
(
"X-Forwarded-Proto"
,
req
.
Header
.
Get
(
"X-Forwarded-Proto"
))
if
isUpgradedConnection
(
req
)
{
r
.
log
.
Debug
(
"upgrading the connnection"
,
zap
.
String
(
"client_ip"
,
req
.
RemoteAddr
))
if
err
:=
tryUpdateConnection
(
req
,
w
,
r
.
endpoint
);
err
!=
nil
{
r
.
log
.
Error
(
"failed to upgrade connection"
,
zap
.
Error
(
err
))
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
return
}
r
.
upstream
.
ServeHTTP
(
w
,
req
)
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment