More headers taken into account
This commit is contained in:
parent
44dba0e53c
commit
9305e5e87f
2 changed files with 33 additions and 11 deletions
|
@ -19,16 +19,21 @@ fn object_headers(
|
|||
let date = UNIX_EPOCH + Duration::from_millis(version.timestamp);
|
||||
let date_str = httpdate::fmt_http_date(date);
|
||||
|
||||
Response::builder()
|
||||
let mut resp = Response::builder()
|
||||
.header(
|
||||
"Content-Type",
|
||||
version_meta.headers.content_type.to_string(),
|
||||
)
|
||||
// TODO: other headers
|
||||
.header("Content-Length", format!("{}", version_meta.size))
|
||||
.header("ETag", version_meta.etag.to_string())
|
||||
.header("Last-Modified", date_str)
|
||||
.header("Accept-Ranges", format!("bytes"))
|
||||
.header("Accept-Ranges", format!("bytes"));
|
||||
|
||||
for (k, v) in version_meta.headers.other.iter() {
|
||||
resp = resp.header(k, v.to_string());
|
||||
}
|
||||
|
||||
resp
|
||||
}
|
||||
|
||||
pub async fn handle_head(
|
||||
|
|
|
@ -24,10 +24,7 @@ pub async fn handle_put(
|
|||
key: &str,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
let version_uuid = gen_uuid();
|
||||
let headers = ObjectVersionHeaders {
|
||||
content_type: get_mime_type(&req)?,
|
||||
other: BTreeMap::new(), // TODO
|
||||
};
|
||||
let headers = get_headers(&req)?;
|
||||
|
||||
let body = req.into_body();
|
||||
|
||||
|
@ -221,10 +218,7 @@ pub async fn handle_create_multipart_upload(
|
|||
key: &str,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
let version_uuid = gen_uuid();
|
||||
let headers = ObjectVersionHeaders {
|
||||
content_type: get_mime_type(&req)?,
|
||||
other: BTreeMap::new(), // TODO
|
||||
};
|
||||
let headers = get_headers(req)?;
|
||||
|
||||
let object_version = ObjectVersion {
|
||||
uuid: version_uuid,
|
||||
|
@ -444,6 +438,29 @@ fn get_mime_type(req: &Request<Body>) -> Result<String, Error> {
|
|||
.to_string())
|
||||
}
|
||||
|
||||
fn get_headers(req: &Request<Body>) -> Result<ObjectVersionHeaders, Error> {
|
||||
let content_type = get_mime_type(req)?;
|
||||
let other_headers = vec![
|
||||
hyper::header::CACHE_CONTROL,
|
||||
hyper::header::CONTENT_DISPOSITION,
|
||||
hyper::header::CONTENT_ENCODING,
|
||||
hyper::header::CONTENT_LANGUAGE,
|
||||
hyper::header::EXPIRES,
|
||||
];
|
||||
let mut other = BTreeMap::new();
|
||||
for h in other_headers.iter() {
|
||||
if let Some(v) = req.headers().get(h) {
|
||||
if let Ok(v_str) = v.to_str() {
|
||||
other.insert(h.to_string(), v_str.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ObjectVersionHeaders {
|
||||
content_type,
|
||||
other: BTreeMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn uuid_from_str(id: &str) -> Result<UUID, ()> {
|
||||
let id_bin = hex::decode(id).map_err(|_| ())?;
|
||||
if id_bin.len() != 32 {
|
||||
|
|
Loading…
Reference in a new issue