cors

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 5 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 cors validates web origins and wraps an HTTP handler with Cross-Origin Resource Sharing headers for the self-hosted online services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateOrigins

func ValidateOrigins(origins []string) error

ValidateOrigins checks that every entry in origins is a unique web origin as a browser sends it: an http or https scheme and a host, with no path, query, fragment, user or wildcard.

func Wrap

func Wrap(next http.Handler, p Policy) http.Handler

Wrap returns an http.Handler that answers CORS preflight requests from p.Origins and sets the CORS response headers on requests from those origins.

Types

type Policy

type Policy struct {
	// Origins are the web origins (such as "https://play.example.com") allowed to call the handler from a browser. When empty, preflight requests are refused and no Access-Control-Allow-Origin header is sent.
	Origins []string
	// Methods are the HTTP methods advertised in Access-Control-Allow-Methods on preflight responses.
	Methods []string
	// Headers are the request headers advertised in Access-Control-Allow-Headers on preflight responses.
	Headers []string
	// ExposeHeaders are the response headers advertised in Access-Control-Expose-Headers on responses to allowed origins.
	ExposeHeaders []string
}

Policy configures CORS handling for an HTTP handler.

Jump to

Keyboard shortcuts

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