httpapi

package
v0.0.0-...-a48de6a Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 57 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFormToken  = errors.New("invalid form token")
	ErrExpiredFormToken  = errors.New("expired form token")
	ErrInvalidInAppToken = errors.New("invalid in-app token")
	ErrExpiredInAppToken = errors.New("expired in-app token")
)

Functions

func ClientIP

func ClientIP(r *http.Request, trustedProxy bool) string

ClientIP uses forwarding headers only when the deployment explicitly trusts its proxy. Otherwise RemoteAddr is authoritative.

func HoneypotEmpty

func HoneypotEmpty(value string) bool

HoneypotEmpty is true only when the hidden bot-trap field is absent or blank.

func HoneypotPassed

func HoneypotPassed(r *http.Request, field string) bool

HoneypotPassed reads a form field without making assumptions about the submitted payload's schema.

func New

func New(store ports.Store, maxBatchSize int) http.Handler

func NewWithOptions

func NewWithOptions(store ports.Store, maxBatchSize int, verifier ports.TokenVerifier, corsAllowedOrigin string) http.Handler

func NewWithSessionTTL

func NewWithSessionTTL(store ports.Store, maxBatchSize int, verifier ports.TokenVerifier, corsAllowedOrigin string, sessionTTL time.Duration, opts ...func(*Server)) http.Handler

func RenderHTML

func RenderHTML(w http.ResponseWriter, template string, vars map[string]any) error

RenderHTML renders a pinned public resource and writes it as HTML. Callers are responsible for loading the immutable version; this helper deliberately does not accept a draft resource.

func SignFormToken

func SignFormToken(formID string, version int, expiresAt time.Time, secret []byte) (string, error)

SignFormToken creates a compact URL-safe token binding a form to its pinned version and expiry. The signed value is also suitable as a submission idempotency key.

func SignInAppToken

func SignInAppToken(tenantID, appID, subject string, expiresAt time.Time, secret []byte) (string, error)

SignInAppToken creates a compact URL-safe token binding a subject (external_id) to a tenant and app for known-subject inbox access.

func WithAIGateway

func WithAIGateway(gateway *ai.Gateway) func(*Server)

WithAIGateway injects a configured gateway for governed AI endpoint tests and deployments that select a custom provider implementation.

func WithExtensionHost

func WithExtensionHost(host *extension.Host) func(*Server)

WithExtensionHost enables the governed extension seams for event ingestion.

func WithPublicGuard

func WithPublicGuard(limiter *IPRateLimiter, captcha CaptchaVerifier, trustedProxy bool) func(*Server)

Types

type CaptchaRequest

type CaptchaRequest struct {
	Token    string
	RemoteIP string
}

type CaptchaVerifier

type CaptchaVerifier interface {
	Verify(context.Context, CaptchaRequest) error
}

CaptchaVerifier is deliberately pluggable; the v1 default is a no-op and deployments may inject a provider-backed verifier.

type FormToken

type FormToken struct {
	FormID    string
	Version   int
	ExpiresAt time.Time
}

func VerifyFormToken

func VerifyFormToken(token, expectedFormID string, expectedVersion int, secret []byte, now time.Time) (FormToken, error)

VerifyFormToken validates the signature, expected form binding, version and expiry. now is injected so expiry behavior remains unit-testable.

func (FormToken) String

func (t FormToken) String() string

type IPRateLimiter

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

IPRateLimiter is a deterministic, in-memory token bucket keyed by client IP. A request consumes one token. It is intended for the public HTTP edge; durable abuse controls can be layered in front of it when needed.

func NewIPRateLimiter

func NewIPRateLimiter(ratePerSecond float64, burst int) *IPRateLimiter

func (*IPRateLimiter) Allow

func (l *IPRateLimiter) Allow(ip string) bool

Allow reports whether one request from ip fits in its bucket.

type InAppToken

type InAppToken struct {
	TenantID  string
	AppID     string
	Subject   string
	ExpiresAt time.Time
}

func VerifyInAppToken

func VerifyInAppToken(token, expectedTenantID, expectedAppID string, secret []byte, now time.Time) (InAppToken, error)

VerifyInAppToken validates the signature, expected tenant/app binding, and expiry. now is injected so expiry behavior remains unit-testable.

type NoopCaptchaVerifier

type NoopCaptchaVerifier struct{}

func (NoopCaptchaVerifier) Verify

type SESNotification

type SESNotification struct {
	EventType string `json:"eventType"`
	Bounce    *struct {
		BounceType        string `json:"bounceType"`
		BounceSubType     string `json:"bounceSubType"`
		BouncedRecipients []struct {
			EmailAddress string `json:"emailAddress"`
		} `json:"bouncedRecipients"`
	} `json:"bounce,omitempty"`
	Complaint *struct {
		ComplainedRecipients []struct {
			EmailAddress string `json:"emailAddress"`
		} `json:"complainedRecipients"`
	} `json:"complaint,omitempty"`
	Delivery *struct {
		Timestamp  string   `json:"timestamp"`
		Recipients []string `json:"recipients"`
	} `json:"delivery,omitempty"`
	Mail struct {
		MessageId string `json:"messageId"`
		Headers   []struct {
			Name  string `json:"name"`
			Value string `json:"value"`
		} `json:"headers"`
	} `json:"mail"`
}

SESNotification represents the nested message payload sent by Amazon SES inside SNS.

type SNSMessage

type SNSMessage struct {
	Type             string `json:"Type"`
	MessageId        string `json:"MessageId"`
	Token            string `json:"Token,omitempty"`
	TopicArn         string `json:"TopicArn"`
	Subject          string `json:"Subject,omitempty"`
	Message          string `json:"Message"`
	Timestamp        string `json:"Timestamp"`
	SignatureVersion string `json:"SignatureVersion"`
	Signature        string `json:"Signature"`
	SigningCertURL   string `json:"SigningCertURL"`
	SubscribeURL     string `json:"SubscribeURL,omitempty"`
}

SNSMessage represents the standard JSON envelope sent by AWS SNS.

type Server

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

func (*Server) SetAllowedTopicARNs

func (s *Server) SetAllowedTopicARNs(arns []string)

SetAllowedTopicARNs configures the allowed Topic ARNs for incoming SNS callbacks.

func (*Server) SetBlobStore

func (s *Server) SetBlobStore(blobs ports.BlobStore)

func (*Server) SetTracking

func (s *Server) SetTracking(secretKey []byte, baseURL string)

SetTracking sets the HMAC secret key and tracking base URL used by link redirect and open pixel handlers.

Jump to

Keyboard shortcuts

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