package cors

import "github.com/streadway/handy/cors"

Package cors contains filters to handle CORS related requests defined from http://www.w3.org/TR/cors/

Index

Constants

const DefaultAllowOrigin = "*"

DefaultAllowOrigin sets Access-Control-Allow-Origin when not configured.

Functions

func Get

func Get(origin string, next http.Handler) http.Handler

Get implements a simple read-only access control policy handling preflight and normal requests with a cache age of 10 minutes for preflight requests. Methods other than HEAD, OPTIONS, GET will return 405.

The origin parameter should be the case-insentive fully qualified origin domain to match or '*' to match any domain.

func Middleware

func Middleware(cfg Config) func(http.Handler) http.Handler

Middleware returns a middleware that applies Config to the request.

Types

type Config

type Config struct {
	// AllowOrigin transforms a request into the Access-Control-Allow-Origin
	// header, default is full access "*".
	AllowOrigin func(*http.Request) string
}

Config parameterizes CORS behavior.

Source Files

cors.go

Version
v0.0.0-20200128134331-0f66f006fb2e (latest)
Published
Jan 28, 2020
Platform
linux/amd64
Imports
3 packages
Last checked
2 months ago

Tools for package owners.