CORS Configuration Rules and Constraints
masterWhen configuring the middleware, observe the following rules:
- Origin Selection: Only one of
AllowAllOrigins,AllowOrigins,AllowOriginFunc, orAllowOriginWithContextFuncshould be set. - Credential Conflict: If
AllowAllOriginsis true, other origin settings are ignored and credentialed requests (cookies, etc.) are not allowed. - Wildcards: If
AllowWildcardis enabled, only one*is allowed per origin string. - Protocols: Use
AllowBrowserExtensions,AllowWebSockets, orAllowFilesto permit non-HTTP(s) protocols as origins. - Validation Errors:
- Setting
AllowAllOriginswhile also settingAllowOriginsor anAllowOriginFuncis invalid. - If neither
AllowAllOrigins,AllowOriginFunc, norAllowOriginsis set, an error is raised. - Using a wildcard in
AllowOriginswithout settingAllowWildcard: true(or using more than one*) will trigger a panic.
- Setting