httputil

package
v0.13.7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicClientPathPrefix     = "/_matrix/client/"
	PublicFederationPathPrefix = "/_matrix/federation/"
	PublicKeyPathPrefix        = "/_matrix/key/"
	PublicMediaPathPrefix      = "/_matrix/media/"
	PublicStaticPath           = "/_matrix/static/"
	PublicWellKnownPrefix      = "/.well-known/matrix/"
	DendriteAdminPathPrefix    = "/_dendrite/"
	SynapseAdminPathPrefix     = "/_synapse/"
)

Variables

View Source
var NotAllowedHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusMethodNotAllowed)
	unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request"))
	_, _ = w.Write(unrecognizedErr)
}))
View Source
var NotFoundCORSHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusNotFound)
	unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request"))
	_, _ = w.Write(unrecognizedErr)
}))

Functions

func MakeAdminAPI added in v0.9.2

func MakeAdminAPI(
	metricsName string, userAPI userapi.QueryAcccessTokenAPI,
	f func(*http.Request, *userapi.Device) util.JSONResponse,
) http.Handler

MakeAdminAPI is a wrapper around MakeAuthAPI which enforces that the request can only be completed by a user that is a server administrator.

func MakeAuthAPI

func MakeAuthAPI(
	metricsName string, userAPI userapi.QueryAcccessTokenAPI,
	f func(*http.Request, *userapi.Device) util.JSONResponse,
	checks ...AuthAPIOption,
) http.Handler

MakeAuthAPI turns a util.JSONRequestHandler function into an http.Handler which authenticates the request.

func MakeExternalAPI

func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse) http.Handler

MakeExternalAPI turns a util.JSONRequestHandler function into an http.Handler. This is used for APIs that are called from the internet.

func MakeHTMLAPI

func MakeHTMLAPI(metricsName string, enableMetrics bool, f func(http.ResponseWriter, *http.Request)) http.Handler

MakeHTMLAPI adds Span metrics to the HTML Handler function This is used to serve HTML alongside JSON error messages

func URLDecodeMapValues

func URLDecodeMapValues(vmap map[string]string) (map[string]string, error)

URLDecodeMapValues is a function that iterates through each of the items in a map, URL decodes the value, and returns a new map with the decoded values under the same key names

func WrapHandlerInBasicAuth

func WrapHandlerInBasicAuth(h http.Handler, b BasicAuth) http.HandlerFunc

WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics

func WrapHandlerInCORS

func WrapHandlerInCORS(h http.Handler) http.HandlerFunc

WrapHandlerInCORS adds CORS headers to all responses, including all error responses. Handles OPTIONS requests directly.

Types

type AuthAPIOption added in v0.10.8

type AuthAPIOption func(opts *AuthAPIOpts)

AuthAPIOption is an option to MakeAuthAPI to add additional checks (e.g. guest access) to verify the user is allowed to do specific things.

func WithAllowGuests added in v0.10.8

func WithAllowGuests() AuthAPIOption

WithAllowGuests checks that guest users have access to this endpoint

type AuthAPIOpts added in v0.10.8

type AuthAPIOpts struct {
	GuestAccessAllowed bool
}

type BasicAuth

type BasicAuth struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

BasicAuth is used for authorization on /metrics handlers

type RateLimits added in v0.6.0

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

func NewRateLimits added in v0.6.0

func NewRateLimits(cfg *config.RateLimiting) *RateLimits

func (*RateLimits) Limit added in v0.6.0

func (l *RateLimits) Limit(req *http.Request, device *userapi.Device) *util.JSONResponse

type Routers added in v0.13.0

type Routers struct {
	Client        *mux.Router
	Federation    *mux.Router
	Keys          *mux.Router
	Media         *mux.Router
	WellKnown     *mux.Router
	Static        *mux.Router
	DendriteAdmin *mux.Router
	SynapseAdmin  *mux.Router
}

func NewRouters added in v0.13.0

func NewRouters() Routers

Jump to

Keyboard shortcuts

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