Documentation
¶
Overview ¶
Package web is the bweb server: a read-only HTTP face over sites kept in bstore buckets. It answers GET and HEAD for anyone, takes each site's behavior from that site's settings, and reads through a Store.
Index ¶
Constants ¶
const HealthPath = "/.well-known/bweb/health"
HealthPath answers 200 on any host name.
Variables ¶
var ErrBusy = errors.New("store: too many reads in flight")
ErrBusy is a read refused because every slot to the store stayed taken for the whole wait.
var ErrSlowDown = errors.New("store: the store refused the read (503)")
ErrSlowDown is a read the store refused because it is shedding load.
Functions ¶
This section is empty.
Types ¶
type Answer ¶
type Answer struct {
Status int
Header http.Header // Content-Type, Content-Length, ETag, Last-Modified, Content-Range, Accept-Ranges
Root string // the object's closure root, hex, when the store names it
Body io.ReadCloser
}
Answer is a store's answer to one read. Body is never nil; the caller closes it.
type Config ¶
type Config struct {
// Listen is the address the server answers on. A web server the
// operator already runs sits in front of it and supplies TLS.
Listen string `json:"listen"`
// Store names where objects are read from.
Store StoreConfig `json:"store"`
// DenyFile is a list of what this server refuses to serve, one entry a
// line (see Deny). Optional.
DenyFile string `json:"deny_file,omitempty"`
// Sites are the sites served. Until a site's settings are read from its
// own record, this file stands in for them.
Sites []Site `json:"sites"`
}
Config is the server's configuration file.
func LoadConfig ¶
LoadConfig reads and checks a configuration file.
type Deny ¶
type Deny struct {
// contains filtered or unexported fields
}
Deny is what a server refuses to serve: a site by its identifier, an object by its closure root, an object by its content hash. One entry a line, "site:<id>", "root:<hex>" or "sha256:<hex>"; blank lines and lines starting with # are skipped. The file is read again when it changes.
type HeaderRule ¶
type HeaderRule struct {
Prefix string `json:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty"`
Set map[string]string `json:"set"`
}
HeaderRule sets response headers on paths with a prefix and a suffix (either may be empty).
type S3Store ¶
type S3Store struct {
// contains filtered or unexported fields
}
S3Store reads from an S3 endpoint, path style, Signature Version 4.
func NewS3Store ¶
func NewS3Store(c StoreConfig) (*S3Store, error)
NewS3Store is a store over the endpoint c names.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server answers readers.
type Site ¶
type Site struct {
ID string `json:"id"` // the site identifier
Hosts []string `json:"hosts"` // the names it answers to, lower case, no port
Bucket string `json:"bucket"` // the bucket's S3 name
Index string `json:"index"` // the index document suffix, "index.html"
Error string `json:"error"` // the error document key, "404.html"; optional
Public bool `json:"public"` // only a public site is served
// Headers are response headers set by path, first match of each name
// wins, in order.
Headers []HeaderRule `json:"headers,omitempty"`
}
Site is one site's settings: the S3 website configuration, with the names it answers to and the bucket it reads.
type Store ¶
type Store interface {
// Read asks for an object. head asks for no body. cond carries the
// request's Range and conditional headers. The answer's Status is 200,
// 206, 304, 404, 412 or 416; anything else is an error.
Read(ctx context.Context, bucket, key string, head bool, cond http.Header) (*Answer, error)
}
Store is where the server reads objects. The S3 store reads through the node's bstore gateway, which proves every answer before it gives it; a reader linked in process is the store to come.
type StoreConfig ¶
type StoreConfig struct {
Endpoint string `json:"endpoint"` // http://127.0.0.1:9000
Region string `json:"region"`
AccessKey string `json:"access_key"`
Secret string `json:"secret,omitempty"`
SecretFile string `json:"secret_file,omitempty"`
// MaxReads bounds the reads in flight to the store (default 24). A
// gateway sheds reads past its own bound (bstore's limits.reads, 32 by
// default); staying under it turns a burst into a short wait here
// instead of refusals there.
MaxReads int `json:"max_reads,omitempty"`
// ReadWaitMS is how long a read waits for a slot before it is refused
// with 503 (default 2000).
ReadWaitMS int `json:"read_wait_ms,omitempty"`
}
StoreConfig names an S3 endpoint: the node's bstore gateway.