Documentation
¶
Overview ¶
Package cors provides cross-origin resource sharing for HTTP requests.
Index ¶
Constants ¶
View Source
const ( // ErrCORS is the error code for cross-origin requests. The error codes in the gateway plugin are custom and use 5 // digits. ErrCORS = 10000 )
Variables ¶
This section is empty.
Functions ¶
func ServerFilter ¶
func ServerFilter(ctx context.Context, req interface{}, handler filter.ServerHandleFunc) (interface{}, error)
ServerFilter sets up server-side CORS validation. Reference for CORS headers: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS
Types ¶
type Options ¶
type Options struct { // AllowOrigins is a list of allowed cross-origin request sources. If empty, it allows all cross-origin requests, // i.e., wildcard *. AllowOrigins []string `yaml:"allow_origins"` // AllowMethods is a list of allowed cross-origin request methods. If not specified, the default value is // []string{"GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"}. AllowMethods []string `yaml:"allow_methods"` // AllowHeaders is a list of headers that can be used in the actual request returned by the preflight request. // If not specified, it allows all preflight request headers. AllowHeaders []string `yaml:"allow_headers"` // AllowCredentials specifies whether to allow credentials to be carried, such as cookies. AllowCredentials bool `yaml:"allow_credentials"` // ExposeHeaders is a list of custom headers that can be obtained in cross-origin requests, such as trpc-ret. ExposeHeaders []string `yaml:"expose_headers"` // MaxAge is the cache time for preflight requests, in seconds. MaxAge int `yaml:"max_age"` }
Options represents the parameter options for the cors plugin.
type Plugin ¶
type Plugin struct { }
Plugin implements the cors plugin for trpc.
func (*Plugin) CheckConfig ¶
CheckConfig validates the plugin configuration and returns the parsed configuration object. Used in the ServerFilter method for parsing.
Click to show internal directories.
Click to hide internal directories.