httputil

package
v0.0.0-...-57f3b98 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: BSD-3-Clause Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const AuthBearer = "Bearer"

Variables

View Source
var (
	ErrTokenInvalid = errors.New("invalid token")
)

Functions

func BearerAuth

func BearerAuth(r *http.Request) (string, bool)

BearerAuth extracts the token from the authorization header. The naming is based on (*http.Request).BasicAuth method.

func CloneRequest

func CloneRequest(r *http.Request) (*http.Request, error)

func ReadRequest

func ReadRequest(r *http.Request) ([]byte, error)

func ReadResponse

func ReadResponse(w *http.Response) ([]byte, error)

func SignJWT

func SignJWT(secret []byte, claims jwt.MapClaims, valid time.Duration) (string, error)

SignJWT signs a JWT with the given claims. Panics if no subject is provided. The expiration is added to the claims.

func VerifyJWT

func VerifyJWT(secret []byte, bearerToken string) (jwt.MapClaims, error)

Types

type Context

type Context[T any] string

func (Context[T]) Value

func (k Context[T]) Value(ctx context.Context) (T, bool)

func (Context[T]) WithValue

func (k Context[T]) WithValue(ctx context.Context, t T) context.Context

type ResponseWriterRecorder

type ResponseWriterRecorder struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriterRecorder

func NewResponseWriterRecorder(w http.ResponseWriter) *ResponseWriterRecorder

func (*ResponseWriterRecorder) Body

func (w *ResponseWriterRecorder) Body() []byte

func (*ResponseWriterRecorder) StatusCode

func (w *ResponseWriterRecorder) StatusCode() int

func (*ResponseWriterRecorder) Unwrap

func (*ResponseWriterRecorder) Write

func (w *ResponseWriterRecorder) Write(b []byte) (int, error)

func (*ResponseWriterRecorder) WriteHeader

func (w *ResponseWriterRecorder) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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