ephttp

package
v1.148.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package ephttp is the HTTP surface of endpoints (#2174): every request to /endpoints/{name}/... and the bot check a public one is answered behind (/botcheck/challenge and /botcheck/solver.js).

A signed_in endpoint answers a browser session or an API key, and the identity the platform found is what the handler reads as req.caller; it never comes from the request body. A public endpoint answers a request carrying an accepted bot check answer in the X-Bot-Check header, or a GET or HEAD with none where the binding opens its reads.

These routes answer their own cross-origin requests from each binding's allowed origins; the platform's CORS layer leaves them alone. No limit here depends on the client's address, which a request behind an ingress and a load balancer does not carry.

Index

Constants

View Source
const (
	// PathPrefix is every endpoint's prefix; a request's path is
	// /endpoints/{name} and what follows it.
	PathPrefix = "/endpoints/"
	// BotCheckPrefix is the bot check's routes.
	BotCheckPrefix = "/botcheck/"
)

The routes.

View Source
const HeaderBotCheck = "X-Bot-Check"

HeaderBotCheck carries a public request's bot check answer.

Variables

View Source
var ErrForbidden = errors.New("the request's credential was refused")

ErrForbidden is what Authenticate returns for a credential that was presented and refused for a reason other than its absence (a browser session without its CSRF token), which is answered 403 rather than 401.

Functions

This section is empty.

Types

type Checker

type Checker interface {
	PublicAllowed(ctx context.Context) (bool, error)
	Issue(ctx context.Context, endpoint string) (botcheck.Challenge, error)
	Verify(ctx context.Context, endpoint, answer string) error
}

Checker is the deployment's bot check.

type Handler

type Handler struct {
	Runner  Runner
	Checker Checker
	// Authenticate is who sent the request: a browser session or an API key.
	// Nil caller and nil error is nobody.
	Authenticate func(r *http.Request) (*eprun.Caller, error)
	// contains filtered or unexported fields
}

Handler answers the routes.

func (*Handler) Mount

func (h *Handler) Mount(mux *http.ServeMux)

Mount registers the routes on mux.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers one request to an endpoint.

type Runner

type Runner interface {
	Resolve(ctx context.Context, name string) (*eprun.Target, error)
	Serve(ctx context.Context, t *eprun.Target, req eprun.Request) eprun.Response
}

Runner is what serves a resolved endpoint.

Jump to

Keyboard shortcuts

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