MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Peer

Function Peer

pkg/webmiddleware/peer.go:26–45  ·  view source on GitHub ↗

Peer sets the remote address as a peer in the request context.

()

Source from the content-addressed store, hash-verified

24
25// Peer sets the remote address as a peer in the request context.
26func Peer() MiddlewareFunc {
27 return func(next http.Handler) http.Handler {
28 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29 p := new(peer.Peer)
30 if addr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr); err == nil {
31 p.Addr = addr
32 }
33 if r.TLS != nil {
34 p.AuthInfo = credentials.TLSInfo{
35 State: *r.TLS,
36 CommonAuthInfo: credentials.CommonAuthInfo{
37 SecurityLevel: credentials.PrivacyAndIntegrity,
38 },
39 }
40 }
41 ctx := peer.NewContext(r.Context(), p)
42 next.ServeHTTP(w, r.WithContext(ctx))
43 })
44 }
45}

Callers 4

NewFunction · 0.92
NewFunction · 0.92
TestPeerFunction · 0.70
TestPeerTLSFunction · 0.70

Calls 2

ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by 2

TestPeerFunction · 0.56
TestPeerTLSFunction · 0.56