good morning!!!!

Skip to content
Snippets Groups Projects
Commit 35ad0853 authored by a's avatar a
Browse files

add original headers for connection to PeerInfo

parent 48c022de
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
}
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment