Documentation
¶
Overview ¶
Package librespeed is a Caddy HTTP handler that serves a speed test: the LibreSpeed backend protocol (garbage, empty, getIP) plus an embedded UI.
Index ¶
Constants ¶
const ( // DefaultMaxUploadSize caps one upload request. LibreSpeed clients send // 20 MB blobs, and Cloudflare rejects bodies over 100 MB. DefaultMaxUploadSize = 64 << 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// MaxUploadSize caps one request body sent to "empty", in bytes.
// Default: 64 MiB.
MaxUploadSize int64 `json:"max_upload_size,omitempty"`
// DisableUI turns off the embedded UI; only the API endpoints answer.
DisableUI bool `json:"disable_ui,omitempty"`
// Servers lists the speed test servers the UI offers to test against.
// Empty means just this one.
Servers []Server `json:"servers,omitempty"`
// contains filtered or unexported fields
}
Handler serves a LibreSpeed-compatible speed test.
API endpoints are matched by the request path's last segment, with or without a ".php" suffix, so the handler works at any path prefix:
- garbage: GET ?ckSize=N streams N MiB of random data (default 4, max 1024)
- empty: drains the request body (upload test) or answers a ping
- getIP: the client's IP, as LibreSpeed's JSON
Every other path serves the embedded UI, unless it is disabled.
func (Handler) CaddyModule ¶
func (Handler) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*Handler) ServeHTTP ¶
ServeHTTP implements caddyhttp.MiddlewareHandler. It is a terminal handler: next is never called.
func (*Handler) UnmarshalCaddyfile ¶
UnmarshalCaddyfile sets up the handler from Caddyfile tokens:
librespeed [<matcher>] {
max_upload_size <size>
ui on|off
server <name> <url>
}
type Server ¶
type Server struct {
// Name is shown in the UI, e.g. "San Francisco".
Name string `json:"name"`
// URL is the absolute base URL the handler answers at, e.g.
// "https://speedtest.example.com/". It must end with "/".
URL string `json:"url"`
}
Server is one entry in the UI's server menu.