You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convenient to get the value of requestid from UserContext
// New creates a new middleware handlerfuncNew(config...Config) fiber.Handler {
// Set default configcfg:=configDefault(config...)
// Return new handlerreturnfunc(c fiber.Ctx) error {
// Don't execute middleware if Next returns trueifcfg.Next!=nil&&cfg.Next(c) {
returnc.Next()
}
// Get id from request, else we generate onerid:=c.Get(cfg.Header)
ifrid=="" {
rid=cfg.Generator()
}
// Set new id to response headerc.Set(cfg.Header, rid)
// Add the request ID to localsc.Locals(requestIDKey, rid)
// Add the request ID to UserContextctx:=context.WithValue(c.UserContext(), cfg.Header, rid)
c.SetUserContext(ctx)
// Continue stackreturnc.Next()
}
}
@ReneWerner87@gaby@efectn I think requestid, keyauth, csrf, session middleware may need this function more, cache, compress, logger, limiter, favicon, pprof, recover, redirect, rewrite, etag, cors and helmet, idempotency, earlydata, encryptcookie may not be so need this function. Maybe we can add those with higher needs first.
gaby
changed the title
📝 [Proposal]: Add support for UserContext in requestid middleware
📝 [Proposal]: Add Support for Context in RequestID Middleware
Nov 12, 2024
Convenient to get the value of requestid from UserContext
Alignment with Express API
N/a
HTTP RFC Standards Compliance
N/a
API Stability
N/a
Feature Examples
Checklist:
The text was updated successfully, but these errors were encountered: