-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorization.rs
41 lines (27 loc) · 989 Bytes
/
authorization.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::borrow::Cow;
use axum::http::{HeaderMap, HeaderValue, header::*};
use crate::errors::{FragmentError, HeaderErrors};
pub async fn ensure_headers(mut headers: &HeaderMap) -> Result<(), FragmentError> {
let header = {
let fields = [
ACCESS_CONTROL_ALLOW_ORIGIN,
CONTENT_LENGTH,
ACCEPT_ENCODING];
for assumed_header in fields.iter() {
if let Some(val) = headers.get(assumed_header){
continue;
}
}
};
Ok(())
}
// return the value of the associated field in the headermap
pub async fn extract_header_fields(headers: &HeaderMap, header_field: HeaderName) -> Result<HeaderValue, FragmentError> {
if let Some(val) = headers.get(&header_field) {
return Ok(val.to_owned());
}
else {
let err_str = Cow::Owned(header_field.as_str().to_string());
return Err(HeaderErrors::HeaderFieldMissing(err_str).into());
}
}