cors

package
v1.1.41 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cors provides functionality for adding CORS response headers into a handler chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOptionsHandler

func CreateOptionsHandler(allowed AllowList, methods ...string) http.HandlerFunc

CreateOptionsHandler creates a generic options handler that takes a list of allowed methods. allowListRE matches hostnames against the given regexp, and provides CORS headers where allowed.

func Handler

func Handler(allowed AllowList) func(http.Handler) http.Handler

Handler inserts Access-Control-Allow-Origin headers into the request response. allowListRE matches hostnames against the given regexp, and provides CORS headers where allowed.

func OriginHost

func OriginHost(r *http.Request) (string, string, error)

OriginHost extracts the origin and origin hostname from a request.

Types

type AllowList

type AllowList func(host string) bool

AllowList allows the user to craft a custom hostname matcher. An AllowList returns true if the requested origin should include valid CORS headers based on an incoming hostname.

func HostByAllowList

func HostByAllowList(allowList map[string]bool) AllowList

HostByAllowList matches the hostname to a given map of allowed hosts.

func HostByRE

func HostByRE(allowListRE *regexp.Regexp) AllowList

HostByRE matches the hostname to a given regular expression

Jump to

Keyboard shortcuts

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