CorsRuleBuilder

Struct CorsRuleBuilder 

Source
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

Source

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.

Source

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:8000
  • https://*.example.com
  • https://*:8765
  • https://*
  • 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.

Source

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:8000
  • https://*.example.com
  • https://*:8765
  • 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.

§Notes

If adding multiple origins, Self::allowed_origins will validate the provided origins more efficiently.

Source

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.

Source

pub fn add_allowed_operation(self, op: CorsOperation) -> Self

Add a CorsOperation to the list of operations the CORS rule allows.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<CorsRule, ValidationError>

Create a CorsRule object.

Trait Implementations§

Source§

impl Debug for CorsRuleBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CorsRuleBuilder

Source§

fn default() -> CorsRuleBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,