origin

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 6 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 origin parses and matches web origins (scheme://host[:port]) with one strict grammar shared by every Credo surface that accepts an allow-list of origins (the WebSocket adapter, CORS). An origin is canonicalized to a lowercase scheme and host and an explicit port; an allow-list pattern may additionally carry one wildcard that stands for exactly one left-most DNS label ("https://*.example.com" matches "https://app.example.com" but not "https://example.com" or "https://a.b.example.com").

Index

Constants

View Source
const MaxLength = 2048

MaxLength bounds the raw text accepted by Parse and ParsePattern.

Variables

This section is empty.

Functions

This section is empty.

Types

type Origin

type Origin struct {
	Scheme string
	Host   string
	Port   uint16
}

Origin is a canonical web origin: lowercase scheme and host, explicit port. IPv6 hosts are stored unbracketed in their canonical textual form.

func Parse

func Parse(raw string) (Origin, error)

Parse canonicalizes a concrete origin such as an Origin header value. Wildcards are rejected.

func (Origin) String

func (o Origin) String() string

String renders the origin as scheme://host[:port], omitting the scheme's default port and bracketing IPv6 hosts.

type Pattern

type Pattern struct {
	Origin   Origin
	Wildcard bool
}

Pattern is one allow-list entry: an exact origin, or a wildcard that matches exactly one left-most DNS label in front of Origin.Host.

func ParsePattern

func ParsePattern(raw string) (Pattern, error)

ParsePattern parses an allow-list entry, accepting one left-most wildcard label.

func (Pattern) Matches

func (p Pattern) Matches(o Origin) bool

Matches reports whether o is allowed by the pattern. Scheme and port must match exactly; the host matches exactly or, for a wildcard pattern, as "<label>." + pattern host where label is one non-empty DNS label.

Jump to

Keyboard shortcuts

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