MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / getRequestID

Method getRequestID

server/router.go:208–232  ·  view source on GitHub ↗

getRequestID tries to read request id from headers or from lambda context or generates a new one if nothing found.

(req *http.Request)

Source from the content-addressed store, hash-verified

206// getRequestID tries to read request id from headers or from lambda
207// context or generates a new one if nothing found.
208func (r *Router) getRequestID(req *http.Request) string {
209 // Get request ID from headers (if any)
210 reqID := req.Header.Get(httpheaders.XRequestID)
211
212 if len(reqID) == 0 || !requestIDRe.MatchString(reqID) {
213 lambdaContextVal := req.Header.Get(httpheaders.XAmznRequestContextHeader)
214
215 if len(lambdaContextVal) > 0 {
216 var lambdaContext struct {
217 RequestID string `json:"requestId"`
218 }
219
220 err := json.Unmarshal([]byte(lambdaContextVal), &lambdaContext)
221 if err == nil && len(lambdaContext.RequestID) > 0 {
222 reqID = lambdaContext.RequestID
223 }
224 }
225 }
226
227 if len(reqID) == 0 || !requestIDRe.MatchString(reqID) {
228 reqID, _ = nanoid.New()
229 }
230
231 return reqID
232}
233
234// replaceRemoteAddr rewrites the req.RemoteAddr property from request headers
235func (r *Router) replaceRemoteAddr(req *http.Request) {

Callers 1

ServeHTTPMethod · 0.95

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected