web

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const HealthPath = "/.well-known/bweb/health"

HealthPath answers 200 on any host name.

Variables

View Source
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.

View Source
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

func LoadConfig(path string) (*Config, error)

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.

func OpenDeny

func OpenDeny(path string) (*Deny, error)

OpenDeny reads a deny list; an empty path is a list that denies nothing.

func (*Deny) Has

func (d *Deny) Has(kind, value string) bool

Has reports whether kind:value is denied.

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.

func (*S3Store) Read

func (s *S3Store) Read(ctx context.Context, bucket, key string, head bool, cond http.Header) (*Answer, error)

type Server

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

Server answers readers.

func NewServer

func NewServer(c *Config, store Store, deny *Deny) *Server

NewServer is a server for the sites of c, reading from store.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

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.

Jump to

Keyboard shortcuts

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