middlewares

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VaryHdr = "Origin, Access-Control-Request-Headers, Access-Control-Request-Method"

Vary http response header is always the same below

Functions

func ApplyBucketCORS added in v1.0.17

func ApplyBucketCORS(be backend.Backend, fallbackOrigin string) fiber.Handler

ApplyBucketCORS retreives the bucket CORS configuration, checks if origin and method meets the cors rules and adds the necessary response headers. CORS check is applied only when 'Origin' request header is present

func ApplyBucketCORSPreflightFallback added in v1.1.0

func ApplyBucketCORSPreflightFallback(be backend.Backend, fallbackOrigin string) fiber.Handler

ApplyBucketCORSPreflightFallback handles CORS preflight (OPTIONS) requests for S3 routes when no per-bucket CORS configuration exists.

If the bucket has no CORS configuration and fallbackOrigin is set, it responds with 204 and: - Access-Control-Allow-Origin: fallbackOrigin - Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method - Access-Control-Allow-Methods: mirrors Access-Control-Request-Method (if present) - Access-Control-Allow-Headers: mirrors Access-Control-Request-Headers (if present)

If the bucket has a CORS configuration (or fallbackOrigin is blank), it calls next so the standard CORS OPTIONS handler can apply bucket-specific rules.

func ApplyDefaultCORS added in v1.1.0

func ApplyDefaultCORS(fallbackOrigin string) fiber.Handler

ApplyDefaultCORS adds a default Access-Control-Allow-Origin header to responses when the provided fallbackOrigin is non-empty.

This is intended for routes that don't have per-bucket CORS configuration (e.g. admin APIs). It will not override an existing Access-Control-Allow-Origin header.

func ApplyDefaultCORSPreflight added in v1.1.0

func ApplyDefaultCORSPreflight(fallbackOrigin string) fiber.Handler

ApplyDefaultCORSPreflight responds to CORS preflight (OPTIONS) requests for routes that don't have per-bucket CORS configuration (e.g. admin APIs).

It uses the provided fallbackOrigin as the Access-Control-Allow-Origin value. It mirrors Access-Control-Request-Method into Access-Control-Allow-Methods and mirrors Access-Control-Request-Headers into Access-Control-Allow-Headers.

func AuthorizePublicBucketAccess added in v1.0.15

func AuthorizePublicBucketAccess(be backend.Backend, s3action string, policyPermission auth.Action, permission auth.Permission, region string, streamBody bool) fiber.Handler

AuthorizePublicBucketAccess checks if the bucket grants public access to anonymous requesters

func BucketObjectNameValidator added in v1.0.15

func BucketObjectNameValidator() fiber.Handler

BucketObjectNameValidator extracts and validates the bucket and object names from the request URI.

func DebugLogger added in v1.0.13

func DebugLogger() fiber.Handler

func DecodeURL

func DecodeURL(ctx *fiber.Ctx) error

DecodeURL url path unescapes the request url for the gateway to handle some special characters

func HostStyleParser added in v1.0.14

func HostStyleParser(virtualDomain string) fiber.Handler

HostStyleParser is a middleware which parses the bucket name from the 'Host' header and appends in the request URL path

func IsAdmin added in v1.0.8

func IsAdmin(action string) fiber.Handler

IsAdmin is a middleware that restricts access to admin APIs, allowing only admin users

func MatchHeader added in v1.0.17

func MatchHeader(key string) fiber.Handler

Evaluates/Matches the requst header

func MatchQueryArgWithValue added in v1.0.17

func MatchQueryArgWithValue(key, val string) fiber.Handler

Evaluates/Matches the requst query param and value

func MatchQueryArgs added in v1.0.17

func MatchQueryArgs(args ...string) fiber.Handler

Evaluates/Matches the provided requst query params

func NewChecksumReader added in v1.0.20

func NewChecksumReader(bodyReader io.Reader, stackedReader io.Reader) io.Reader

NewChecksumReader wraps a stackedReader and returns a reader that preserves checksum behavior when the *original* bodyReader implemented ChecksumReader.

If bodyReader already supports ChecksumReader, we wrap stackedReader with MockChecksumReader so that reading continues from stackedReader, but Algorithm() and Checksum() still delegate to the underlying reader.

If bodyReader is not a ChecksumReader, we simply return stackedReader.

func ParseAcl added in v1.0.17

func ParseAcl(be backend.Backend) fiber.Handler

ParseAcl retreives the bucket acl and stores in the context locals if no bucket is found, it returns 'NoSuchBucket'

func SetDefaultValues added in v1.0.15

func SetDefaultValues(root RootUserConfig, region string) fiber.Handler

func VerifyChecksums added in v1.0.19

func VerifyChecksums(streamBody bool, requireBody bool, requireChecksum bool) fiber.Handler

VerifyChecksums parses, validates, and calculates the Content-MD5 and x-amz-checksum-* headers. Additionally, it ensures that the request body is not empty for actions that require a non-empty body. For large data actions(PutObject, UploadPart), it wraps the body reader to handle Content-MD5: the x-amz-checksum-* headers are explicitly processed by the backend.

func VerifyPresignedV4Signature

func VerifyPresignedV4Signature(root RootUserConfig, iam auth.IAMService, region string, streamBody bool) fiber.Handler

func VerifyV4Signature

func VerifyV4Signature(root RootUserConfig, iam auth.IAMService, region string, streamBody bool, requireContentSha256 bool) fiber.Handler

Types

type ChecksumReader added in v1.0.20

type ChecksumReader interface {
	io.Reader
	Algorithm() string
	Checksum() string
}

ChecksumReader extends io.Reader with checksum-related metadata. It is used to differentiate normal readers from readers that can report a checksum and the algorithm used to produce it.

type MockChecksumReader added in v1.0.20

type MockChecksumReader struct {
	// contains filtered or unexported fields
}

MockChecksumReader is a wrapper around an io.Reader that forwards Read() but also conditionally exposes checksum metadata if the underlying reader implements the ChecksumReader interface.

func (*MockChecksumReader) Algorithm added in v1.0.20

func (rr *MockChecksumReader) Algorithm() string

Algorithm returns the checksum algorithm used by the underlying reader, but only if the wrapped reader implements ChecksumReader.

func (*MockChecksumReader) Checksum added in v1.0.20

func (rr *MockChecksumReader) Checksum() string

Checksum returns the checksum value from the underlying reader, if it implements ChecksumReader. Otherwise returns an empty string.

func (*MockChecksumReader) Read added in v1.0.20

func (rr *MockChecksumReader) Read(buffer []byte) (int, error)

Read simply forwards data reads to the underlying reader.

type RootUserConfig

type RootUserConfig struct {
	Access string
	Secret string
}

Jump to

Keyboard shortcuts

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