package cors

import "github.com/google/martian/v3/cors"

Package cors provides CORS support for http.Handlers.

Index

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is an http.Handler that wraps other http.Handlers and provides CORS support.

func NewHandler

func NewHandler(h http.Handler) *Handler

NewHandler wraps an existing http.Handler allowing it to be requested via CORS.

func (*Handler) AllowCredentials

func (h *Handler) AllowCredentials(allow bool)

AllowCredentials allows cookies to be read by the CORS request.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP determines if a request is a CORS request (normal or preflight) and sets the appropriate Access-Control-Allow-* headers. It will send the request to the underlying handler in all cases, except for a preflight (OPTIONS) request.

func (*Handler) SetOrigin

func (h *Handler) SetOrigin(origin string)

SetOrigin sets the origin(s) to allow when requested with CORS.

Source Files

cors.go

Version
v3.3.3 (latest)
Published
Aug 16, 2022
Platform
linux/amd64
Imports
1 packages
Last checked
5 hours ago

Tools for package owners.