Documentation
¶
Overview ¶
Package httpserver is the HTTP entry of ermite: the router, the security headers, the request log and the graceful shutdown. Routes are added here as the other adapters arrive: /-/health, /robots.txt and the routes given in Config.
Index ¶
Constants ¶
const APIPrefix = "/-/api"
APIPrefix is where the API is mounted.
const DefaultRobotsTxt = `` /* 769-byte string literal not displayed */
DefaultRobotsTxt keeps crawlers on the home page, the repository summaries, issues, merge requests and releases, and off the views that are endless (every file and directory at every commit, every pair of commits, every diff layout) or costly (raw files, downloads, CI logs, Git transfers).
In RFC 9309 patterns "*" matches any characters, slashes included, so "/*/blob/" also covers the /<owner>/<repo>/blob/ form. For the same reason a bare "/*/tree" would match any path containing "/tree" (a release tag "tree-v1"); each such view is the triplet "X$", "X/" and "X?" instead. The RFC has no single-segment class, so a path whose last segment is exactly "tree", "commits", "refs" or "actions" (a release tag named "tree") is still blocked.
"/*/merge-requests/*?" blocks the query variants of a merge request page (diff layout, file, comment anchor), which each render a full diff; the bare page and the list (/<repo>/merge-requests?page=) stay allowed.
ShutdownTimeout is how long Run waits for requests in flight after the context ends.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
Check reports whether a dependency works. A nil result means healthy.
type Config ¶
type Config struct {
// VideoHosts are exact external video hosts; nil uses the defaults.
VideoHosts []string
// Addr is the listen address, "host:port".
Addr string
// PublicURL is the public base URL of the server. When it is https://,
// every response carries Strict-Transport-Security.
PublicURL string
// HealthChecks run on GET /-/health, at most once per healthCacheTTL
// (the answer is cached, the endpoint being unauthenticated); one
// failure answers 503.
HealthChecks []Check
// Routes are added to the router next to /-/health.
Routes []Route
// RobotsTxt is the body of /robots.txt; nil serves DefaultRobotsTxt.
RobotsTxt []byte
// API serves the ConnectRPC API under /-/api/ (the prefix is stripped, so
// it sees "/ermite.RepoService/ListRepos"). Nil serves none.
API http.Handler
// OnShutdown functions run, each in its own goroutine, when the graceful
// shutdown begins. Use them to end long-lived responses such as event
// streams, which the shutdown would otherwise wait for.
OnShutdown []func()
}
Config configures a Server.
type Route ¶
type Route struct {
// Pattern is a net/http.ServeMux pattern, such as "GET /{repo}/info/refs".
// It must not overlap the /-/ routes of the server.
Pattern string
Handler http.Handler
}
Route mounts a handler on the router.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server of ermite.
func (*Server) Handler ¶
Handler returns the root handler, for tests.
func (*Server) Run ¶
Run listens on the configured address and serves until ctx ends, then shuts down gracefully within ShutdownTimeout. It returns nil after a clean shutdown. The logger of ctx is used for the server and its requests.
Source Files
¶
- health.go
- middleware.go
- robots.go
- server.go