good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
open
jrpc
Commits
35ad0853
Commit
35ad0853
authored
2 years ago
by
a
Browse files
Options
Downloads
Patches
Plain Diff
add original headers for connection to PeerInfo
parent
48c022de
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
http.go
+7
-1
7 additions, 1 deletion
http.go
server.go
+3
-0
3 additions, 0 deletions
server.go
websocket.go
+7
-3
7 additions, 3 deletions
websocket.go
with
17 additions
and
4 deletions
http.go
+
7
−
1
View file @
35ad0853
...
...
@@ -282,8 +282,14 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
connInfo
:=
PeerInfo
{
Transport
:
"http"
,
RemoteAddr
:
r
.
RemoteAddr
}
connInfo
.
HTTP
.
Version
=
r
.
Proto
connInfo
.
HTTP
.
Host
=
r
.
Host
connInfo
.
HTTP
.
Origin
=
r
.
Header
.
Get
(
"Origin"
)
connInfo
.
HTTP
.
Origin
=
r
.
Header
.
Get
(
"X-Real-Ip"
)
if
connInfo
.
HTTP
.
Origin
==
""
{
connInfo
.
HTTP
.
Origin
=
r
.
Header
.
Get
(
"X-Forwarded-For"
)
}
connInfo
.
HTTP
.
UserAgent
=
r
.
Header
.
Get
(
"User-Agent"
)
// the headers used
connInfo
.
HTTP
.
Headers
=
r
.
Header
ctx
:=
r
.
Context
()
ctx
=
context
.
WithValue
(
ctx
,
peerInfoContextKey
{},
connInfo
)
...
...
This diff is collapsed.
Click to expand it.
server.go
+
3
−
0
View file @
35ad0853
...
...
@@ -3,6 +3,7 @@ package jrpc
import
(
"context"
"io"
"net/http"
"sync/atomic"
"git.tuxpa.in/a/zlog/log"
...
...
@@ -141,6 +142,8 @@ type PeerInfo struct {
UserAgent
string
Origin
string
Host
string
Headers
http
.
Header
}
}
...
...
This diff is collapsed.
Click to expand it.
websocket.go
+
7
−
3
View file @
35ad0853
...
...
@@ -120,6 +120,7 @@ func wsClientHeaders(endpoint, origin string) (string, http.Header, error) {
header
:=
make
(
http
.
Header
)
if
origin
!=
""
{
header
.
Add
(
"origin"
,
origin
)
header
.
Add
(
"X-Forwarded-For"
,
origin
)
}
if
endpointURL
.
User
!=
nil
{
b64auth
:=
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
endpointURL
.
User
.
String
()))
...
...
@@ -171,14 +172,17 @@ func newWebsocketCodec(ctx context.Context, c *websocket.Conn, host string, req
conn
:
c
,
pingReset
:
make
(
chan
struct
{},
1
),
info
:
PeerInfo
{
Transport
:
"ws"
,
RemoteAddr
:
conn
.
RemoteAddr
()
.
String
(),
Transport
:
"ws"
,
},
}
// Fill in connection details.
wc
.
info
.
HTTP
.
Host
=
host
wc
.
info
.
HTTP
.
Origin
=
req
.
Get
(
"Origin"
)
wc
.
info
.
HTTP
.
Origin
=
req
.
Get
(
"X-Real-Ip"
)
if
wc
.
info
.
HTTP
.
Origin
==
""
{
wc
.
info
.
HTTP
.
Origin
=
req
.
Get
(
"X-Forwarded-For"
)
}
wc
.
info
.
HTTP
.
UserAgent
=
req
.
Get
(
"User-Agent"
)
wc
.
info
.
HTTP
.
Headers
=
req
// Start pinger.
go
heartbeat
(
ctx
,
c
,
wsPingInterval
)
return
wc
...
...
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