origins

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 7 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 origins reads the browser origins: the CORS settings every environment shares and, for each environment, its hosts and the browser origins it admits. They are written in the proxyfile, or in an origins file it names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PatternPCRE added in v2.2.0

func PatternPCRE(pattern string) string

PatternPCRE is the PCRE2 expression of an origin pattern, which takes what PatternRegex takes. PatternRegex reads each * as .*, which PCRE2 tries at every length when the text does not match: 64 patterns of two * each stopped HAProxy 3.2.26 and 3.4.7 with one Origin of 8 KB, and held a worker of nginx 1.30.6 and 1.31.8 for 17 to 30 s with one of 6,321 bytes (measured). A text matches the pattern when it starts with the part before the first *, ends with the part after the last, and holds each part between them in order; the first place of each such part leaves the most room to the others, so each is matched there by an atomic group, which PCRE2 never tries again elsewhere, and the time grows with the Origin's length alone.

func PatternRegex

func PatternRegex(pattern string) string

PatternRegex keeps the meaning a Spring allowed-origin-pattern has: every character literal but *, which matches any run, dots included.

func SameOriginRegex

func SameOriginRegex(host string) string

SameOriginRegex admits the service's own origin on one of its hosts, on either scheme and any port.

Types

type CORS

type CORS struct {
	AllowMethods, AllowHeaders, ExposeHeaders, MaxAge string
	KeyPos                                            map[string]model.Pos
}

CORS is the cors key: each value "" when not written. KeyPos is where each written key is, by its path (cors.max_age), which a generator names a value's refusal by, so that it points at the value's own key: in block style the cors mapping starts on its first key's line, another key's for every value but the first. KeyPos is nil when cors is not written.

type Environment

type Environment struct {
	Name                     string
	Hosts, Origins, Patterns []string  // nil when not written or empty
	Pos                      model.Pos // the environment's mapping in an origins file; its key in the proxyfile
}

func (Environment) Listed added in v2.2.0

func (e Environment) Listed() bool

Listed says whether the environment admits origins by a list, origins or patterns: only such an environment answers a browser with CORS headers, so each generator writes those lines for it alone.

type File

type File struct {
	CORS         CORS
	Environments []Environment // written order
}

File is the origins after reading, from either place, with every rule below checked.

func Inline

func Inline(cors, environments *tree.Node) (*File, []model.Problem)

Inline reads the origins written in the proxyfile: environments is its origins mapping, which the format check accepted, and cors its cors mapping, or nil when not written. Each entry is one environment, named by its key.

func Read

func Read(path string) (*File, *tree.Node, []model.Problem)

Read reads the origins file at path, which is JSON read as YAML so that a problem names its line. It returns the origins and the tree the format check accepted, in which render.Read finds the keys its target refuses, or the problems of the first step that finds any: reading the file, its syntax, the format check, then the rules below.

Jump to

Keyboard shortcuts

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