Documentation ¶
Overview ¶
Cors package to validate CORS requests and provide the correct headers in the response
Index ¶
- Constants
- func GetCorsAllowCredentials(prefix string) string
- func GetCorsAllowHeaders(prefix string) string
- func GetCorsAllowMethods(prefix string) string
- func GetCorsAllowOrigin(prefix string) string
- func GetCorsExposeHeaders(prefix string) string
- func GetCorsMaxAge(prefix string) string
- func HasOriginHeader(r *http.Request) bool
- type Cors
Constants ¶
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" )
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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