Public request in context

This commit is contained in:
Erika Harker 2026-04-15 15:17:08 -05:00
parent 3d4b3651f2
commit 1cc668a0e1
5 changed files with 26 additions and 24 deletions

10
core.go
View file

@ -242,7 +242,7 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
reqCtx := &requestContext{
chainIndex: 0,
}
// Prepare the chain nodes for this request
mw := app.hooks.GetHooks()
for _, v := range mw {
@ -252,11 +252,11 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
for _, v := range rhs {
reqCtx.chainNodes = append(reqCtx.chainNodes, v)
}
// Store chain state in request context
ctx := &Context{
Request: &Request{
httpRequest: r.WithContext(context.WithValue(r.Context(), "goffeeChain", reqCtx)),
HttpRequest: r.WithContext(context.WithValue(r.Context(), "goffeeChain", reqCtx)),
httpPathParams: ps,
},
Response: &Response{
@ -279,7 +279,7 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
}
ctx.prepare(ctx)
// Execute the first handler in the chain
if len(reqCtx.chainNodes) > 0 {
n := reqCtx.chainNodes[0]
@ -392,7 +392,7 @@ func UseHook(mw Hook) {
// Next advances to the next middleware or controller in the chain and invokes it with the given context if available.
func (app *App) Next(c *Context) {
// Get request-specific chain state from context
if reqCtx, ok := c.Request.httpRequest.Context().Value("goffeeChain").(*requestContext); ok {
if reqCtx, ok := c.Request.HttpRequest.Context().Value("goffeeChain").(*requestContext); ok {
reqCtx.chainIndex++
if reqCtx.chainIndex < len(reqCtx.chainNodes) {
n := reqCtx.chainNodes[reqCtx.chainIndex]