cors

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Cors package to validate CORS requests and provide the correct headers in the response

Index

Constants

View Source
const (
	ORIGIN_HEADER                           string = "Origin"
	ACCESS_CONTROL_REQUEST_METHOD_HEADER    string = "Access-Control-Request-Method"
	ACCESS_CONTROL_REQUEST_HEADER_HEADER    string = "Access-Control-Request-Headers"
	ACCESS_CONTROL_ALLOW_ORIGIN_HEADER      string = "Access-Control-Allow-Origin"
	ACCESS_CONTROL_ALLOW_METHODS_HEADER     string = "Access-Control-Allow-Methods"
	ACCESS_CONTROL_ALLOW_HEADERS_HEADER     string = "Access-Control-Allow-Headers"
	ACCESS_CONTROL_EXPOSE_HEADERS_HEADER    string = "Access-Control-Expose-Headers"
	ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER string = "Access-Control-Allow-Credentials"
	ACCESS_CONTROL_MAX_AGE_HEADER           string = "Access-Control-Max-Age"
)
View Source
const (
	CORS_ALLOW_ORIGIN_KEY          string = "CORS_ALLOW_ORIGIN"
	CORS_ALLOW_ORIGIN_DEFAULT      string = "*"
	CORS_ALLOW_METHODS_KEY         string = "CORS_ALLOW_METHODS"
	CORS_ALLOW_METHODS_DEFAULT     string = "POST, GET, OPTIONS, PUT, DELETE, PATCH"
	CORS_ALLOW_HEADERS_KEY         string = "CORS_ALLOW_HEADERS"
	CORS_EXPOSE_HEADERS_KEY        string = "CORS_EXPOSE_HEADERS"
	CORS_ALLOW_HEADERS_DEFAULT     string = "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, X-Requested-With, Accept, Accept-Language"
	CORS_EXPOSE_HEADERS_DEFAULT    string = ""
	CORS_ALLOW_CREDENTIALS_KEY     string = "CORS_ALLOW_CREDENTIALS"
	CORS_ALLOW_CREDENTIALS_DEFAULT string = "false"
	CORS_MAX_AGE_KEY               string = "CORS_MAX_AGE"
	CORS_MAX_AGE_DEFAULT           string = ""
)

List of constants default values that can be overriden by environment variables

Variables

This section is empty.

Functions

func GetCorsAllowCredentials

func GetCorsAllowCredentials(prefix string) string

GetCorsAllowCredentials get the value for CORS 'AllowCredentials' param from environment variable and the default BS_CORS_ALLOW_CREDENTIALS_DEFAULT will be used if not found

func GetCorsAllowHeaders

func GetCorsAllowHeaders(prefix string) string

GetCorsAllowHeaders get the value for CORS 'AllowHeaders' param from environment variable and the default BS_CORS_ALLOW_HEADERS_DEFAULT will be used if not found

func GetCorsAllowMethods

func GetCorsAllowMethods(prefix string) string

GetCorsAllowMethods get the allowed method for CORS from environment variable and the default BS_CORS_ALLOW_METHODS_DEFAULT will be used if not found

func GetCorsAllowOrigin

func GetCorsAllowOrigin(prefix string) string

GetCorsAllowOrigin get the value for CORS 'AllowOrigin' param from environment variable and the default BS_CORS_ALLOW_ORIGIN_DEFAULT will be used if not found

func GetCorsExposeHeaders

func GetCorsExposeHeaders(prefix string) string

GetCorsExposeHeaders get the value for CORS 'ExposeHeaders' param from environment variable and the default BS_CORS_EXPOSE_HEADERS_DEFAULT will be used if not found

func GetCorsMaxAge

func GetCorsMaxAge(prefix string) string

GetCorsMaxAge get the value for CORS 'Max Age' param from environment variable and the default BS_CORS_ALLOW_CREDENTIALS_DEFAULT will be used if not found

func HasOriginHeader

func HasOriginHeader(r *http.Request) bool

HasOriginHeader returns true if the request has Origin header, false otherwise

Types

type Cors

type Cors interface {
	// HandlePreflight Handles the preflight OPTIONS request
	HandlePreflight(w http.ResponseWriter, r *http.Request)
	// WriteCorsActualRequestHeaders writes the needed request headers for the CORS support
	WriteCorsActualRequestHeaders(w http.ResponseWriter)
}

CORS interface

func New

func New(prefix string, log logger.Logger) Cors

Cors constructor

Jump to

Keyboard shortcuts

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