pub struct CorsRuleBuilder { /* private fields */ }Expand description
Create a CorsRule.
See https://www.backblaze.com/b2/docs/cors_rules.html for further information on CORS and file access via the B2 service.
Implementations§
Source§impl CorsRuleBuilder
impl CorsRuleBuilder
Sourcepub fn name(
self,
name: impl Into<String>,
) -> Result<Self, CorsRuleValidationError>
pub fn name( self, name: impl Into<String>, ) -> Result<Self, CorsRuleValidationError>
Create a human-recognizeable name for the CORS rule.
Names can contains any ASCII letters, numbers, and ‘-’. It must be between 6 and 50 characters, inclusive. Names beginning with “b2-” are reserved.
Sourcepub fn allowed_origins(
self,
origins: impl Into<Vec<String>>,
) -> Result<Self, ValidationError>
pub fn allowed_origins( self, origins: impl Into<Vec<String>>, ) -> Result<Self, ValidationError>
Set the list of origins covered by this rule.
Examples of valid origins:
http://www.example.com:8000https://*.example.comhttps://*:8765https://*https*
If an entry is *, there can be no other entries. There can be no more
than one https entry. An entry cannot have more than one ‘*’.
Note that an origin such as https is broader than an origin of
https://* because the latter is limited to the HTTPS scheme’s default
port, but the former is valid for all ports.
At least one origin is required in a CORS rule.
Sourcepub fn add_allowed_origin(
self,
origin: impl Into<String>,
) -> Result<Self, ValidationError>
pub fn add_allowed_origin( self, origin: impl Into<String>, ) -> Result<Self, ValidationError>
Add an origin to the list of allowed origins.
Examples of valid origins:
http://www.example.com:8000https://*.example.comhttps://*:8765https://**
If an entry is *, there can be no other entries. There can be no more
than one https entry. An entry cannot have more than one ‘*’.
Note that an origin such as https is broader than an origin of
https://* because the latter is limited to the HTTPS scheme’s default
port, but the former is valid for all ports.
At least one origin is required in a CORS rule.
§Notes
If adding multiple origins, Self::allowed_origins will validate the provided origins more efficiently.
Sourcepub fn allowed_operations(
self,
ops: Vec<CorsOperation>,
) -> Result<Self, ValidationError>
pub fn allowed_operations( self, ops: Vec<CorsOperation>, ) -> Result<Self, ValidationError>
Set the list of operations the CORS rule allows.
If the provided list is empty, returns ValidationError::MissingData.
Sourcepub fn add_allowed_operation(self, op: CorsOperation) -> Self
pub fn add_allowed_operation(self, op: CorsOperation) -> Self
Add a CorsOperation to the list of operations the CORS rule allows.
Sourcepub fn allowed_headers<H>(
self,
headers: impl Into<Vec<String>>,
) -> Result<Self, BadHeaderName>
pub fn allowed_headers<H>( self, headers: impl Into<Vec<String>>, ) -> Result<Self, BadHeaderName>
Set the list of headers allowed in a pre-flight OPTION requests’
Access-Control-Request-Headers header value.
Each header may be:
- A complete header name
- A header name ending with an asterisk (
*) to match multiple headers - An asterisk (`*) to match any header
If an entry is *, there can be no other entries.
The default is an empty list (no headers are allowed).
Sourcepub fn add_allowed_header(
self,
header: impl Into<String>,
) -> Result<Self, BadHeaderName>
pub fn add_allowed_header( self, header: impl Into<String>, ) -> Result<Self, BadHeaderName>
Add a header to the list of headers allowed in a pre-flight OPTION
requests’ Access-Control-Request-Headers header value.
The header may be:
- A complete header name
- A header name ending with an asterisk (
*) to match multipl headers - An asterisk (`*) to match any header
If an entry is *, there can be no other entries.
By default, no headers are allowed.
Sourcepub fn exposed_headers(
self,
headers: impl Into<Vec<String>>,
) -> Result<Self, BadHeaderName>
pub fn exposed_headers( self, headers: impl Into<Vec<String>>, ) -> Result<Self, BadHeaderName>
Set the list of headers that may be exposed to an application inside the client.
Each entry must be a complete header name. If the list is empty, no headers will be exposed.
Sourcepub fn add_exposed_header(
self,
header: impl Into<String>,
) -> Result<Self, BadHeaderName>
pub fn add_exposed_header( self, header: impl Into<String>, ) -> Result<Self, BadHeaderName>
Add a header that may be exposed to an application inside the client.
Each entry must be a complete header name.
Sourcepub fn max_age(self, age: Duration) -> Result<Self, ValidationError>
pub fn max_age(self, age: Duration) -> Result<Self, ValidationError>
Set the maximum duration the browser may cache the response to a preflight request.
The age must be non-negative and no more than one day.