79754502

Date: 2025-09-03 11:06:24
Score: 3.5
Natty:
Report link

I have same problem with you. I'm not sure if this is correct but this is how I did it

Use middleware to save Header or RawBody to context.Context

        Middlewares: huma.Middlewares{whMdw.SaveHeaderToContext, whMdw.SaveBodyToContext},
func SaveHeaderToContext(ctx huma.Context, next func(huma.Context)) {
    webhookHeader := make(map[string]string)
    ctx.EachHeader(func(name, value string) {
        webhookHeader[name] = value
    })
    ctx = huma.WithValue(ctx, HeaderKey, webhookHeader)

    next(ctx)
}

func SaveBodyToContext(ctx huma.Context, next func(huma.Context)) {
    reader := ctx.BodyReader()
    if reader == nil {
        next(ctx)
        return
    }

    bodyBytes, err := io.ReadAll(reader)
    if err != nil {
        next(ctx)
        return
    }
    ctx = huma.WithValue(ctx, RawBodyKey, bodyBytes)

    next(ctx)
}

And, you can get this data in ctx

Reasons:
  • Blacklisted phrase (1): I have same problem
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have same problem
  • Low reputation (1):
Posted by: Nhã Lê Thanh