aws_lambda_router/
cors.rs1#[derive(Debug, Clone)]
3pub struct CorsConfig {
4 pub allow_origin: String,
5 pub allow_methods: Vec<String>,
6 pub allow_headers: Vec<String>,
7 pub max_age: u32,
8 pub allow_credentials: bool,
9}
10
11impl CorsConfig {
12 pub fn new() -> Self {
13 Self {
14 allow_origin: "*".to_string(),
15 allow_methods: vec![
16 "GET".to_string(),
17 "POST".to_string(),
18 "PUT".to_string(),
19 "DELETE".to_string(),
20 "OPTIONS".to_string(),
21 ],
22 allow_headers: vec![
23 "Content-Type".to_string(),
24 "Authorization".to_string(),
25 ],
26 max_age: 3600,
27 allow_credentials: false,
28 }
29 }
30
31 pub fn allow_origin(mut self, origin: impl Into<String>) -> Self {
32 self.allow_origin = origin.into();
33 self
34 }
35
36 pub fn allow_methods(mut self, methods: Vec<String>) -> Self {
37 self.allow_methods = methods;
38 self
39 }
40
41 pub fn allow_headers(mut self, headers: Vec<String>) -> Self {
42 self.allow_headers = headers;
43 self
44 }
45
46 pub fn max_age(mut self, max_age: u32) -> Self {
47 self.max_age = max_age;
48 self
49 }
50
51 pub fn allow_credentials(mut self, allow: bool) -> Self {
52 self.allow_credentials = allow;
53 self
54 }
55}
56
57impl Default for CorsConfig {
58 fn default() -> Self {
59 Self::new()
60 }
61}