MCPcopy
hub / github.com/lxc/incus / CreateRequestor

Function CreateRequestor

internal/server/request/request.go:12–52  ·  view source on GitHub ↗

CreateRequestor extracts the lifecycle event requestor data from an http.Request context.

(r *http.Request)

Source from the content-addressed store, hash-verified

10
11// CreateRequestor extracts the lifecycle event requestor data from an http.Request context.
12func CreateRequestor(r *http.Request) *api.EventLifecycleRequestor {
13 ctx := r.Context()
14 requestor := &api.EventLifecycleRequestor{}
15
16 // Normal requestor.
17 val, ok := ctx.Value(CtxUsername).(string)
18 if ok {
19 requestor.Username = val
20 }
21
22 val, ok = ctx.Value(CtxProtocol).(string)
23 if ok {
24 requestor.Protocol = val
25 }
26
27 requestor.Address = r.RemoteAddr
28
29 // Forwarded requestor override.
30 val, ok = ctx.Value(CtxForwardedUsername).(string)
31 if ok {
32 requestor.Username = val
33 }
34
35 val, ok = ctx.Value(CtxForwardedProtocol).(string)
36 if ok {
37 requestor.Protocol = val
38 }
39
40 val, ok = ctx.Value(CtxForwardedAddress).(string)
41 if ok {
42 requestor.Address = val
43 }
44
45 // Strip port from address.
46 host, _, err := net.SplitHostPort(requestor.Address)
47 if err == nil {
48 requestor.Address = host
49 }
50
51 return requestor
52}
53
54// SaveConnectionInContext can be set as the ConnContext field of a http.Server to set the connection
55// in the request context for later use.

Callers 15

validateSubnetMethod · 0.92
SetRequestorMethod · 0.92
IsSameRequestorMethod · 0.92
storagePoolBucketsPostFunction · 0.92
storagePoolBucketPutFunction · 0.92
storagePoolBucketDeleteFunction · 0.92
storagePoolBucketKeyPutFunction · 0.92
instanceMetadataGetFunction · 0.92
doInstanceMetadataUpdateFunction · 0.92

Calls 1

ContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…