use crate::s3::error::ValidationErr;
use crate::s3::response_traits::{
HasBucket, HasChecksumHeaders, HasEtagFromHeaders, HasObject, HasRegion, HasVersion,
};
use crate::s3::types::{S3Request, UploadId};
use crate::s3::utils::get_text_result;
use crate::{impl_from_s3response, impl_from_s3response_with_size, impl_has_s3fields};
use bytes::{Buf, Bytes};
use http::HeaderMap;
use xmltree::Element;
#[derive(Clone, Debug)]
pub struct S3Response1 {
pub(crate) request: S3Request,
pub(crate) headers: HeaderMap,
pub(crate) body: Bytes,
}
impl_from_s3response!(S3Response1);
impl_has_s3fields!(S3Response1);
impl HasBucket for S3Response1 {}
impl HasObject for S3Response1 {}
impl HasRegion for S3Response1 {}
impl HasVersion for S3Response1 {}
impl HasEtagFromHeaders for S3Response1 {}
impl HasChecksumHeaders for S3Response1 {}
#[derive(Clone, Debug)]
pub struct S3Response1WithSize {
request: S3Request,
headers: HeaderMap,
body: Bytes,
pub(crate) object_size: u64,
}
impl_from_s3response_with_size!(S3Response1WithSize);
impl_has_s3fields!(S3Response1WithSize);
impl HasBucket for S3Response1WithSize {}
impl HasObject for S3Response1WithSize {}
impl HasRegion for S3Response1WithSize {}
impl HasVersion for S3Response1WithSize {}
impl HasEtagFromHeaders for S3Response1WithSize {}
impl HasChecksumHeaders for S3Response1WithSize {}
impl S3Response1WithSize {
pub fn new(response: S3Response1, object_size: u64) -> Self {
Self {
request: response.request,
headers: response.headers,
body: response.body,
object_size,
}
}
pub fn object_size(&self) -> u64 {
self.object_size
}
}
#[derive(Clone, Debug)]
pub struct S3MultipartResponse {
request: S3Request,
headers: HeaderMap,
body: Bytes,
}
impl_from_s3response!(S3MultipartResponse);
impl_has_s3fields!(S3MultipartResponse);
impl HasBucket for S3MultipartResponse {}
impl HasObject for S3MultipartResponse {}
impl HasRegion for S3MultipartResponse {}
impl HasVersion for S3MultipartResponse {}
impl HasEtagFromHeaders for S3MultipartResponse {}
impl HasChecksumHeaders for S3MultipartResponse {}
impl S3MultipartResponse {
pub async fn upload_id(&self) -> Result<UploadId, ValidationErr> {
let root = Element::parse(self.body.clone().reader())?;
let s: String = get_text_result(&root, "UploadId")
.map_err(|e| ValidationErr::InvalidUploadId(e.to_string()))?;
Ok(UploadId::new_unchecked(s))
}
}
pub type PutObjectResponse = S3Response1;
pub type CreateMultipartUploadResponse = S3MultipartResponse;
pub type AbortMultipartUploadResponse = S3MultipartResponse;
pub type CompleteMultipartUploadResponse = S3Response1;
pub type UploadPartResponse = S3Response1;
pub type PutObjectContentResponse = S3Response1WithSize;