httpsvc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(tunnel string, vhost, control, opsH http.Handler, st *httpStats, route func(string) (string, bool), lim *liveLimits) (http.Handler, error)

Handler sends the tunnel name to the ops API and frp control, and a host that route matches to vhost, which is frps's site proxy in this process. route returns the published name that routes host: host itself, or a wildcard. Any other host gets no response at all. A nil route passes every host to vhost as its own site. A nil st counts nothing; a nil lim uses the default limits; a nil control leaves frp control out.

func NodeName added in v0.3.0

func NodeName(tunnel string) func(tls.ConnectionState) string

NodeName names the dark node of a verified client certificate of tunnel: <name> of spiffe://<tunnel>/node/<name>, or "" for any other.

func NodeOnly

func NodeOnly(tunnel string) func(tls.ConnectionState) error

NodeOnly accepts a verified client certificate only when it carries a dark-node identity of tunnel: spiffe://<tunnel>/node/<name>. It guards frp control on TCP 443 and, through frps, on QUIC.

func ProxyError added in v0.3.0

func ProxyError(r *http.Request, err error)

ProxyError is frps's error hook (OnProxyError): every request frps could not proxy, on the request's goroutine. It logs one line that says where it failed and for whom, and counts it for the site. frps then answers 502 or 504, or, when the body broke off, cuts the response.

func QUICCertificate

func QUICCertificate(ctx context.Context, cfg config.Config, domains *Domains) (func(*tls.ClientHelloInfo) (*tls.Certificate, error), error)

QUICCertificate is what frps presents on UDP 443, and only to the tunnel name: a probe naming anything else gets no certificate. It is the certmagic config TCP 443 uses, so both present the same certificate and a renewal on either is used by the other's next handshake.

func Serve

func Serve(ctx context.Context, cfg config.Config, policy []byte, filt edgeFilter, domains *Domains, control, vhost http.Handler, apply ops.ApplyFunc, reboot func(), more Extras) error

Serve runs the HTTP and HTTPS servers until ctx ends. policy is the policy.yml cfg holds, as stored; apply stores and applies a new one.

Types

type Domains

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

Domains is the set of hostnames that currently have an HTTP route. frps reports a name when its first route appears and when its last route disappears. Under tls: acme, the first report of an exact name manages its certificate: loaded from disk, or obtained. certmagic's timer then checks it every renew_interval and renews it once it is due. The last report stops that; the certificate stays on disk.

func NewDomains

func NewDomains(tunnel string) *Domains

func (*Domains) Allowed

func (d *Domains) Allowed(name string) bool

Allowed is the tunnel name, or an exact name a dark node currently has registered: the names that may have a certificate.

func (*Domains) Domain

func (d *Domains) Domain(domain string, added bool)

Domain is the frps vhost callback. added is true when the name gains its first route and false when it loses its last. frps calls it with its router lock held, so the obtain runs in the background.

func (*Domains) Known

func (d *Domains) Known(name string) bool

Known is a name the edge answers for: the tunnel or a routed site. Anything else gets no certificate, no status code, and no bytes.

func (*Domains) Published added in v0.3.0

func (d *Domains) Published() int

Published counts the names dark nodes publish now.

func (*Domains) Route added in v0.3.0

func (d *Domains) Route(host string) (string, bool)

Route returns the published name frps routes host by, matched the way its router matches: the exact name, then each wildcard parent down to three labels (a.b.example.com tries *.b.example.com, then *.example.com), then a catch-all "*".

func (*Domains) Routed

func (d *Domains) Routed(host string) bool

Routed reports whether frps has a route for host.

type Extras added in v0.4.0

type Extras struct {
	Metrics []func(*metrics.Writer)
	Status  map[string]func() any
}

Extras are what the rest of the edge adds to the ops API: metrics writers (the tunnel, the clock), and status keys with their values.

Jump to

Keyboard shortcuts

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