aws_sdk_lambda/types/_cors.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// <p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">cross-origin resource sharing (CORS)</a> settings for your Lambda function URL. Use CORS to grant access to your function URL from any origin. You can also use CORS to control access for specific HTTP headers and methods in requests to your function URL.</p>
4#[non_exhaustive]
5#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
6pub struct Cors {
7    /// <p>Whether to allow cookies or other credentials in requests to your function URL. The default is <code>false</code>.</p>
8    pub allow_credentials: ::std::option::Option<bool>,
9    /// <p>The HTTP headers that origins can include in requests to your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
10    pub allow_headers: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
11    /// <p>The HTTP methods that are allowed when calling your function URL. For example: <code>GET</code>, <code>POST</code>, <code>DELETE</code>, or the wildcard character (<code>*</code>).</p>
12    pub allow_methods: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
13    /// <p>The origins that can access your function URL. You can list any number of specific origins, separated by a comma. For example: <code>https://www.example.com</code>, <code>http://localhost:60905</code>.</p>
14    /// <p>Alternatively, you can grant access to all origins using the wildcard character (<code>*</code>).</p>
15    pub allow_origins: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
16    /// <p>The HTTP headers in your function response that you want to expose to origins that call your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
17    pub expose_headers: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
18    /// <p>The maximum amount of time, in seconds, that web browsers can cache results of a preflight request. By default, this is set to <code>0</code>, which means that the browser doesn't cache results.</p>
19    pub max_age: ::std::option::Option<i32>,
20}
21impl Cors {
22    /// <p>Whether to allow cookies or other credentials in requests to your function URL. The default is <code>false</code>.</p>
23    pub fn allow_credentials(&self) -> ::std::option::Option<bool> {
24        self.allow_credentials
25    }
26    /// <p>The HTTP headers that origins can include in requests to your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
27    ///
28    /// If no value was sent for this field, a default will be set. If you want to determine if no value was sent, use `.allow_headers.is_none()`.
29    pub fn allow_headers(&self) -> &[::std::string::String] {
30        self.allow_headers.as_deref().unwrap_or_default()
31    }
32    /// <p>The HTTP methods that are allowed when calling your function URL. For example: <code>GET</code>, <code>POST</code>, <code>DELETE</code>, or the wildcard character (<code>*</code>).</p>
33    ///
34    /// If no value was sent for this field, a default will be set. If you want to determine if no value was sent, use `.allow_methods.is_none()`.
35    pub fn allow_methods(&self) -> &[::std::string::String] {
36        self.allow_methods.as_deref().unwrap_or_default()
37    }
38    /// <p>The origins that can access your function URL. You can list any number of specific origins, separated by a comma. For example: <code>https://www.example.com</code>, <code>http://localhost:60905</code>.</p>
39    /// <p>Alternatively, you can grant access to all origins using the wildcard character (<code>*</code>).</p>
40    ///
41    /// If no value was sent for this field, a default will be set. If you want to determine if no value was sent, use `.allow_origins.is_none()`.
42    pub fn allow_origins(&self) -> &[::std::string::String] {
43        self.allow_origins.as_deref().unwrap_or_default()
44    }
45    /// <p>The HTTP headers in your function response that you want to expose to origins that call your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
46    ///
47    /// If no value was sent for this field, a default will be set. If you want to determine if no value was sent, use `.expose_headers.is_none()`.
48    pub fn expose_headers(&self) -> &[::std::string::String] {
49        self.expose_headers.as_deref().unwrap_or_default()
50    }
51    /// <p>The maximum amount of time, in seconds, that web browsers can cache results of a preflight request. By default, this is set to <code>0</code>, which means that the browser doesn't cache results.</p>
52    pub fn max_age(&self) -> ::std::option::Option<i32> {
53        self.max_age
54    }
55}
56impl Cors {
57    /// Creates a new builder-style object to manufacture [`Cors`](crate::types::Cors).
58    pub fn builder() -> crate::types::builders::CorsBuilder {
59        crate::types::builders::CorsBuilder::default()
60    }
61}
62
63/// A builder for [`Cors`](crate::types::Cors).
64#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
65#[non_exhaustive]
66pub struct CorsBuilder {
67    pub(crate) allow_credentials: ::std::option::Option<bool>,
68    pub(crate) allow_headers: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
69    pub(crate) allow_methods: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
70    pub(crate) allow_origins: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
71    pub(crate) expose_headers: ::std::option::Option<::std::vec::Vec<::std::string::String>>,
72    pub(crate) max_age: ::std::option::Option<i32>,
73}
74impl CorsBuilder {
75    /// <p>Whether to allow cookies or other credentials in requests to your function URL. The default is <code>false</code>.</p>
76    pub fn allow_credentials(mut self, input: bool) -> Self {
77        self.allow_credentials = ::std::option::Option::Some(input);
78        self
79    }
80    /// <p>Whether to allow cookies or other credentials in requests to your function URL. The default is <code>false</code>.</p>
81    pub fn set_allow_credentials(mut self, input: ::std::option::Option<bool>) -> Self {
82        self.allow_credentials = input;
83        self
84    }
85    /// <p>Whether to allow cookies or other credentials in requests to your function URL. The default is <code>false</code>.</p>
86    pub fn get_allow_credentials(&self) -> &::std::option::Option<bool> {
87        &self.allow_credentials
88    }
89    /// Appends an item to `allow_headers`.
90    ///
91    /// To override the contents of this collection use [`set_allow_headers`](Self::set_allow_headers).
92    ///
93    /// <p>The HTTP headers that origins can include in requests to your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
94    pub fn allow_headers(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
95        let mut v = self.allow_headers.unwrap_or_default();
96        v.push(input.into());
97        self.allow_headers = ::std::option::Option::Some(v);
98        self
99    }
100    /// <p>The HTTP headers that origins can include in requests to your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
101    pub fn set_allow_headers(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
102        self.allow_headers = input;
103        self
104    }
105    /// <p>The HTTP headers that origins can include in requests to your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
106    pub fn get_allow_headers(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
107        &self.allow_headers
108    }
109    /// Appends an item to `allow_methods`.
110    ///
111    /// To override the contents of this collection use [`set_allow_methods`](Self::set_allow_methods).
112    ///
113    /// <p>The HTTP methods that are allowed when calling your function URL. For example: <code>GET</code>, <code>POST</code>, <code>DELETE</code>, or the wildcard character (<code>*</code>).</p>
114    pub fn allow_methods(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
115        let mut v = self.allow_methods.unwrap_or_default();
116        v.push(input.into());
117        self.allow_methods = ::std::option::Option::Some(v);
118        self
119    }
120    /// <p>The HTTP methods that are allowed when calling your function URL. For example: <code>GET</code>, <code>POST</code>, <code>DELETE</code>, or the wildcard character (<code>*</code>).</p>
121    pub fn set_allow_methods(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
122        self.allow_methods = input;
123        self
124    }
125    /// <p>The HTTP methods that are allowed when calling your function URL. For example: <code>GET</code>, <code>POST</code>, <code>DELETE</code>, or the wildcard character (<code>*</code>).</p>
126    pub fn get_allow_methods(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
127        &self.allow_methods
128    }
129    /// Appends an item to `allow_origins`.
130    ///
131    /// To override the contents of this collection use [`set_allow_origins`](Self::set_allow_origins).
132    ///
133    /// <p>The origins that can access your function URL. You can list any number of specific origins, separated by a comma. For example: <code>https://www.example.com</code>, <code>http://localhost:60905</code>.</p>
134    /// <p>Alternatively, you can grant access to all origins using the wildcard character (<code>*</code>).</p>
135    pub fn allow_origins(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
136        let mut v = self.allow_origins.unwrap_or_default();
137        v.push(input.into());
138        self.allow_origins = ::std::option::Option::Some(v);
139        self
140    }
141    /// <p>The origins that can access your function URL. You can list any number of specific origins, separated by a comma. For example: <code>https://www.example.com</code>, <code>http://localhost:60905</code>.</p>
142    /// <p>Alternatively, you can grant access to all origins using the wildcard character (<code>*</code>).</p>
143    pub fn set_allow_origins(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
144        self.allow_origins = input;
145        self
146    }
147    /// <p>The origins that can access your function URL. You can list any number of specific origins, separated by a comma. For example: <code>https://www.example.com</code>, <code>http://localhost:60905</code>.</p>
148    /// <p>Alternatively, you can grant access to all origins using the wildcard character (<code>*</code>).</p>
149    pub fn get_allow_origins(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
150        &self.allow_origins
151    }
152    /// Appends an item to `expose_headers`.
153    ///
154    /// To override the contents of this collection use [`set_expose_headers`](Self::set_expose_headers).
155    ///
156    /// <p>The HTTP headers in your function response that you want to expose to origins that call your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
157    pub fn expose_headers(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
158        let mut v = self.expose_headers.unwrap_or_default();
159        v.push(input.into());
160        self.expose_headers = ::std::option::Option::Some(v);
161        self
162    }
163    /// <p>The HTTP headers in your function response that you want to expose to origins that call your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
164    pub fn set_expose_headers(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
165        self.expose_headers = input;
166        self
167    }
168    /// <p>The HTTP headers in your function response that you want to expose to origins that call your function URL. For example: <code>Date</code>, <code>Keep-Alive</code>, <code>X-Custom-Header</code>.</p>
169    pub fn get_expose_headers(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
170        &self.expose_headers
171    }
172    /// <p>The maximum amount of time, in seconds, that web browsers can cache results of a preflight request. By default, this is set to <code>0</code>, which means that the browser doesn't cache results.</p>
173    pub fn max_age(mut self, input: i32) -> Self {
174        self.max_age = ::std::option::Option::Some(input);
175        self
176    }
177    /// <p>The maximum amount of time, in seconds, that web browsers can cache results of a preflight request. By default, this is set to <code>0</code>, which means that the browser doesn't cache results.</p>
178    pub fn set_max_age(mut self, input: ::std::option::Option<i32>) -> Self {
179        self.max_age = input;
180        self
181    }
182    /// <p>The maximum amount of time, in seconds, that web browsers can cache results of a preflight request. By default, this is set to <code>0</code>, which means that the browser doesn't cache results.</p>
183    pub fn get_max_age(&self) -> &::std::option::Option<i32> {
184        &self.max_age
185    }
186    /// Consumes the builder and constructs a [`Cors`](crate::types::Cors).
187    pub fn build(self) -> crate::types::Cors {
188        crate::types::Cors {
189            allow_credentials: self.allow_credentials,
190            allow_headers: self.allow_headers,
191            allow_methods: self.allow_methods,
192            allow_origins: self.allow_origins,
193            expose_headers: self.expose_headers,
194            max_age: self.max_age,
195        }
196    }
197}