httpctx

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httpctx provides shared helpers for extracting authentication context from gin-based HTTP handlers.

Both the native AgentBox API and the E2B-compatible API use oapi-codegen's strict server mode, which passes *gin.Context directly as context.Context. These helpers safely extract AuthInfo regardless of whether the context has been wrapped by context.WithValue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthFrom

func AuthFrom(ctx context.Context) domain.AuthInfo

AuthFrom extracts domain.AuthInfo from the context.

It first tries a direct *gin.Context type assertion (fast path when the context has not been wrapped). If that fails, it uses ctx.Value("auth") which traverses through any context.WithValue layers and reaches the underlying gin.Context's key store.

func GinFromCtx

func GinFromCtx(ctx context.Context) *gin.Context

GinFromCtx extracts the *gin.Context from a context.Context. Returns nil if the context is not or does not wrap a *gin.Context.

func WithClientCancel added in v0.0.13

func WithClientCancel(ctx context.Context) context.Context

WithClientCancel returns a context that is cancelled when the HTTP client goes away, for a handler that waits on something long enough to outlive its caller.

The strict server hands each handler the *gin.Context itself, and with the engine's ContextWithFallback off (the default) its Done/Err/Deadline report nothing: a client that disconnects is invisible to the handler, which keeps waiting and completes work nobody will receive. For create that means a sandbox claimed, armed and held for a caller that never learns its ID, so it stays allocated until the idle sweep.

Cancellation is opt-in per handler rather than switched on for the engine: handlers that make several writes, and roll back with the same context, would otherwise abort half-way and fail the rollback too. Values (auth, the gin context itself) still resolve through the *gin.Context, so AuthFrom and GinFromCtx keep working on the result.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL