httputil

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CallInternalProxyAPI added in v0.9.2

func CallInternalProxyAPI[reqtype, restype any, errtype error](name, url string, client *http.Client, ctx context.Context, request *reqtype) (restype, error)

func CallInternalRPCAPI added in v0.9.2

func CallInternalRPCAPI[reqtype, restype any](name, url string, client *http.Client, ctx context.Context, request *reqtype, response *restype) error

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,
) 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, f func(http.ResponseWriter, *http.Request) *util.JSONResponse) http.Handler

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

func MakeInternalAPI

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

MakeInternalAPI turns a util.JSONRequestHandler function into an http.Handler. This is used for APIs that are internal to dendrite. If we are passed a tracing context in the request headers then we use that as the parent of any tracing spans we create.

func MakeInternalProxyAPI added in v0.9.2

func MakeInternalProxyAPI[reqtype, restype any](metricsName string, f func(context.Context, *reqtype) (*restype, error)) http.Handler

func MakeInternalRPCAPI added in v0.9.2

func MakeInternalRPCAPI[reqtype, restype any](metricsName string, f func(context.Context, *reqtype, *restype) error) http.Handler

func PostJSON

func PostJSON[reqtype, restype any, errtype error](
	ctx context.Context, span opentracing.Span, httpClient *http.Client,
	apiURL string, request *reqtype, response *restype,
) error

PostJSON performs a POST request with JSON on an internal HTTP API. The error will match the errtype if returned from the remote API, or will be a different type if there was a problem reaching the API.

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 BasicAuth

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

BasicAuth is used for authorization on /metrics handlers

type InternalAPIError added in v0.9.2

type InternalAPIError struct {
	Type    string
	Message string
}

func (InternalAPIError) Error added in v0.9.2

func (e InternalAPIError) Error() string

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

Jump to

Keyboard shortcuts

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