Support for PostObject #222

Merged
lx merged 14 commits from trinity-1686a/garage:post-object into main 2022-02-21 22:02:31 +00:00
Showing only changes of commit e0aee72a9c - Show all commits

View file

@ -43,7 +43,14 @@ pub async fn handle_post_object(
let mut multipart = Multipart::with_constraints(body, boundary, constraints);
let mut params = HeaderMap::new();
while let Some(field) = multipart.next_field().await? {
let field = loop {
let field = if let Some(field) = multipart.next_field().await? {
field
} else {
return Err(Error::BadRequest(
"Request did not contain a file".to_owned(),
));
};
let name: HeaderName = if let Some(Ok(name)) = field.name().map(TryInto::try_into) {
name
} else {
@ -62,8 +69,10 @@ pub async fn handle_post_object(
}
}
}
continue;
} else {
break field;
}
};
// Current part is file. Do some checks before handling to PutObject code
let key = params
@ -235,7 +244,6 @@ pub async fn handle_post_object(
.and_then(|h| h.to_str().ok())
.unwrap_or("204");
let builder = Response::builder()
.status(StatusCode::OK)
.header(header::LOCATION, location)
.header(header::ETAG, etag);
match action {
@ -248,12 +256,7 @@ pub async fn handle_post_object(
}
};
return Ok(resp);
}
Err(Error::BadRequest(
"Request did not contain a file".to_owned(),
))
Ok(resp)
}
#[derive(Deserialize)]