MCPcopy
hub / github.com/pocketbase/pocketbase / initRequestInfo

Method initRequestInfo

core/event_request.go:109–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107}
108
109func (e *RequestEvent) initRequestInfo() error {
110 infoCtx, _ := e.Get(RequestEventKeyInfoContext).(string)
111 if infoCtx == "" {
112 infoCtx = RequestInfoContextDefault
113 }
114
115 info := &RequestInfo{
116 Context: infoCtx,
117 Method: e.Request.Method,
118 Query: map[string]string{},
119 Headers: map[string]string{},
120 Body: map[string]any{},
121 }
122
123 if err := e.BindBody(&info.Body); err != nil {
124 return err
125 }
126
127 // extract the first value of all query params
128 query := e.Request.URL.Query()
129 for k, v := range query {
130 if len(v) > 0 {
131 info.Query[k] = v[0]
132 }
133 }
134
135 // extract the first value of all headers and normalizes the keys
136 // ("X-Token" is converted to "x_token")
137 for k, v := range e.Request.Header {
138 if len(v) > 0 {
139 info.Headers[inflector.Snakecase(k)] = v[0]
140 }
141 }
142
143 info.Auth = e.Auth
144
145 e.cachedRequestInfo = info
146
147 return nil
148}
149
150// -------------------------------------------------------------------
151

Callers 1

RequestInfoMethod · 0.95

Calls 4

SnakecaseFunction · 0.92
BindBodyMethod · 0.80
QueryMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected