Rename fields and fix clippy
This commit is contained in:
parent
f270df21c0
commit
1ca3691637
|
@ -193,9 +193,9 @@ impl CorsRule {
|
||||||
GarageCorsRule {
|
GarageCorsRule {
|
||||||
id: self.id.as_ref().map(|x| x.0.to_owned()),
|
id: self.id.as_ref().map(|x| x.0.to_owned()),
|
||||||
max_age_seconds: self.max_age_seconds.as_ref().map(|x| x.0 as u64),
|
max_age_seconds: self.max_age_seconds.as_ref().map(|x| x.0 as u64),
|
||||||
allowed_origins: convert_vec(&self.allowed_origins),
|
allow_origins: convert_vec(&self.allowed_origins),
|
||||||
allowed_methods: convert_vec(&self.allowed_methods),
|
allow_methods: convert_vec(&self.allowed_methods),
|
||||||
allowed_headers: convert_vec(&self.allowed_headers),
|
allow_headers: convert_vec(&self.allowed_headers),
|
||||||
expose_headers: convert_vec(&self.expose_headers),
|
expose_headers: convert_vec(&self.expose_headers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,9 +209,9 @@ impl CorsRule {
|
||||||
Self {
|
Self {
|
||||||
id: rule.id.as_ref().map(|x| Value(x.clone())),
|
id: rule.id.as_ref().map(|x| Value(x.clone())),
|
||||||
max_age_seconds: rule.max_age_seconds.map(|x| IntValue(x as i64)),
|
max_age_seconds: rule.max_age_seconds.map(|x| IntValue(x as i64)),
|
||||||
allowed_origins: convert_vec(&rule.allowed_origins),
|
allowed_origins: convert_vec(&rule.allow_origins),
|
||||||
allowed_methods: convert_vec(&rule.allowed_methods),
|
allowed_methods: convert_vec(&rule.allow_methods),
|
||||||
allowed_headers: convert_vec(&rule.allowed_headers),
|
allowed_headers: convert_vec(&rule.allow_headers),
|
||||||
expose_headers: convert_vec(&rule.expose_headers),
|
expose_headers: convert_vec(&rule.expose_headers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,10 +227,10 @@ where
|
||||||
HI: Iterator<Item = S>,
|
HI: Iterator<Item = S>,
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
{
|
{
|
||||||
rule.allowed_origins.iter().any(|x| x == "*" || x == origin)
|
rule.allow_origins.iter().any(|x| x == "*" || x == origin)
|
||||||
&& rule.allowed_methods.iter().any(|x| x == "*" || x == method)
|
&& rule.allow_methods.iter().any(|x| x == "*" || x == method)
|
||||||
&& request_headers.all(|h| {
|
&& request_headers.all(|h| {
|
||||||
rule.allowed_headers
|
rule.allow_headers
|
||||||
.iter()
|
.iter()
|
||||||
.any(|x| x == "*" || x == h.as_ref())
|
.any(|x| x == "*" || x == h.as_ref())
|
||||||
})
|
})
|
||||||
|
@ -243,15 +243,15 @@ pub fn add_cors_headers(
|
||||||
let h = resp.headers_mut();
|
let h = resp.headers_mut();
|
||||||
h.insert(
|
h.insert(
|
||||||
ACCESS_CONTROL_ALLOW_ORIGIN,
|
ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||||
rule.allowed_origins.join(", ").parse()?,
|
rule.allow_origins.join(", ").parse()?,
|
||||||
);
|
);
|
||||||
h.insert(
|
h.insert(
|
||||||
ACCESS_CONTROL_ALLOW_METHODS,
|
ACCESS_CONTROL_ALLOW_METHODS,
|
||||||
rule.allowed_methods.join(", ").parse()?,
|
rule.allow_methods.join(", ").parse()?,
|
||||||
);
|
);
|
||||||
h.insert(
|
h.insert(
|
||||||
ACCESS_CONTROL_ALLOW_HEADERS,
|
ACCESS_CONTROL_ALLOW_HEADERS,
|
||||||
rule.allowed_headers.join(", ").parse()?,
|
rule.allow_headers.join(", ").parse()?,
|
||||||
);
|
);
|
||||||
h.insert(
|
h.insert(
|
||||||
ACCESS_CONTROL_EXPOSE_HEADERS,
|
ACCESS_CONTROL_EXPOSE_HEADERS,
|
||||||
|
|
|
@ -57,9 +57,9 @@ pub struct WebsiteConfig {
|
||||||
pub struct CorsRule {
|
pub struct CorsRule {
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub max_age_seconds: Option<u64>,
|
pub max_age_seconds: Option<u64>,
|
||||||
pub allowed_origins: Vec<String>,
|
pub allow_origins: Vec<String>,
|
||||||
pub allowed_methods: Vec<String>,
|
pub allow_methods: Vec<String>,
|
||||||
pub allowed_headers: Vec<String>,
|
pub allow_headers: Vec<String>,
|
||||||
pub expose_headers: Vec<String>,
|
pub expose_headers: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,19 +210,19 @@ async fn serve_file(garage: Arc<Garage>, req: &Request<Body>) -> Result<Response
|
||||||
if let Some(origin) = req.headers().get("Origin") {
|
if let Some(origin) = req.headers().get("Origin") {
|
||||||
let origin = origin.to_str()?;
|
let origin = origin.to_str()?;
|
||||||
let request_headers = match req.headers().get(ACCESS_CONTROL_REQUEST_HEADERS) {
|
let request_headers = match req.headers().get(ACCESS_CONTROL_REQUEST_HEADERS) {
|
||||||
Some(h) => h.to_str()?.split(",").map(|h| h.trim()).collect::<Vec<_>>(),
|
Some(h) => h.to_str()?.split(',').map(|h| h.trim()).collect::<Vec<_>>(),
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
let matching_rule = cors_config.iter().find(|rule| {
|
let matching_rule = cors_config.iter().find(|rule| {
|
||||||
cors_rule_matches(
|
cors_rule_matches(
|
||||||
rule,
|
rule,
|
||||||
&origin,
|
origin,
|
||||||
&req.method().to_string(),
|
&req.method().to_string(),
|
||||||
request_headers.iter(),
|
request_headers.iter(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
if let Some(rule) = matching_rule {
|
if let Some(rule) = matching_rule {
|
||||||
add_cors_headers(&mut resp, &rule)
|
add_cors_headers(&mut resp, rule)
|
||||||
.ok_or_internal_error("Invalid CORS configuration")?;
|
.ok_or_internal_error("Invalid CORS configuration")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,21 +244,20 @@ fn handle_options(bucket: &Bucket, req: &Request<Body>) -> Result<Response<Body>
|
||||||
.ok_or_bad_request("Missing Access-Control-Request-Method header")?
|
.ok_or_bad_request("Missing Access-Control-Request-Method header")?
|
||||||
.to_str()?;
|
.to_str()?;
|
||||||
let request_headers = match req.headers().get(ACCESS_CONTROL_REQUEST_HEADERS) {
|
let request_headers = match req.headers().get(ACCESS_CONTROL_REQUEST_HEADERS) {
|
||||||
Some(h) => h.to_str()?.split(",").map(|h| h.trim()).collect::<Vec<_>>(),
|
Some(h) => h.to_str()?.split(',').map(|h| h.trim()).collect::<Vec<_>>(),
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(cors_config) = bucket.params().unwrap().cors_config.get() {
|
if let Some(cors_config) = bucket.params().unwrap().cors_config.get() {
|
||||||
let matching_rule = cors_config
|
let matching_rule = cors_config
|
||||||
.iter()
|
.iter()
|
||||||
.find(|rule| cors_rule_matches(rule, &origin, &request_method, request_headers.iter()));
|
.find(|rule| cors_rule_matches(rule, origin, request_method, request_headers.iter()));
|
||||||
if let Some(rule) = matching_rule {
|
if let Some(rule) = matching_rule {
|
||||||
let mut resp = Response::builder()
|
let mut resp = Response::builder()
|
||||||
.status(StatusCode::OK)
|
.status(StatusCode::OK)
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.map_err(ApiError::from)?;
|
.map_err(ApiError::from)?;
|
||||||
add_cors_headers(&mut resp, &rule)
|
add_cors_headers(&mut resp, rule).ok_or_internal_error("Invalid CORS configuration")?;
|
||||||
.ok_or_internal_error("Invalid CORS configuration")?;
|
|
||||||
return Ok(resp);
|
return Ok(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue