pageserver

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 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 pageserver puts the desktop page in front of the service: Proxy forwards the page's API calls to the service's socket (the desktop app's web view and a Server both use it), and a Server serves the page itself to a browser, on a loopback port only whoever holds its link can use.

The service never listens on a network port; a Server does, for the page, so it lets in only requests that carry its cookie, which a one-time link (OpenURL) hands out. Requests must also name the Server's own address as their host (no DNS rebinding) and, when they say where they come from, come from the page (no other site, not even another port on 127.0.0.1, whose requests a browser would send the cookie with).

A Server speaks only HTTP/2, over TLS: a browser keeps at most six HTTP/1.1 connections to a host, and each of the page's open streams (a turn, its watches) held one, so a seventh request waited for one to end and the window froze. HTTP/2 carries them all on one connection. The certificate is the Server's own, made in memory as it starts and never written down; the window that shows the page trusts that one certificate by its fingerprint (Fingerprint), so a program that took the port after the Server stopped couldn't pose as it.

Index

Constants

View Source
const CertLifetime = 30 * 24 * time.Hour

CertLifetime is how long a Server's certificate is valid. The window trusts it by its fingerprint, not by its dates; a Server lives as long as the app that started it.

View Source
const HostPrefix = "/host/"

HostPrefix is where Options.Host answers: what the page asks of the program serving it (opening folders, the service's controls).

View Source
const TicketTTL = time.Minute

TicketTTL is how long a link from OpenURL lasts unused.

Variables

This section is empty.

Functions

func Fingerprint added in v0.8.0

func Fingerprint(der []byte) string

Fingerprint is a certificate's SHA-256 as upper-case hex pairs joined by colons, as Node's X509Certificate.fingerprint256 writes it.

func Proxy

func Proxy(path string) http.Handler

Proxy forwards the page's API requests to the service's Unix socket (a web view can't open one itself), streaming responses as they come. Anything else is not found: the page's own files are served by a Server.

Types

type Options

type Options struct {
	// Page is the page's files, index.html at the root.
	Page fs.FS
	// Socket is the service's socket, for Proxy.
	Socket string
	// Host answers under HostPrefix (nil: not found).
	Host http.Handler
	// Addr is where to listen: 127.0.0.1:0 (any free port) by default.
	// Only a loopback address is allowed.
	Addr string
}

Options are what a Server serves.

type Server

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

Server is the page on a loopback port. Close it when done.

func Start

func Start(o Options) (*Server, error)

Start listens and serves in the background.

func (*Server) Close

func (s *Server) Close() error

Close stops the server.

func (*Server) Fingerprint added in v0.8.0

func (s *Server) Fingerprint() string

Fingerprint is the SHA-256 fingerprint of the Server's certificate, the one the window showing the page trusts (pageserver's Fingerprint).

func (*Server) OpenURL

func (s *Server) OpenURL() string

OpenURL is a link that opens the page once: it lets the browser in (a cookie) and then goes to the page, so the link in the address bar and the history is the page's, not one that would let anyone in again.

func (*Server) Origin

func (s *Server) Origin() string

Origin is the page's origin: https://127.0.0.1:port.

func (*Server) ServeHTTP

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

ServeHTTP checks a request and serves it: a link from OpenURL, the API, the host's calls or the page.

func (*Server) Transport added in v0.8.0

func (s *Server) Transport() *http.Transport

Transport reaches this Server, and nothing else, over HTTP/2: what a Go client (a test, say) uses in place of the window.

Jump to

Keyboard shortcuts

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