use crate::read_resume_policy::{ReadResumePolicy, Recommended};
use crate::storage::checksum::details::{Checksum, Crc32c};
use gax::{
backoff_policy::BackoffPolicy,
retry_policy::RetryPolicy,
retry_throttler::{AdaptiveThrottler, SharedRetryThrottler},
};
use std::sync::{Arc, Mutex};
#[derive(Clone, Debug)]
pub struct RequestOptions {
pub(crate) retry_policy: Arc<dyn RetryPolicy>,
pub(crate) backoff_policy: Arc<dyn BackoffPolicy>,
pub(crate) retry_throttler: SharedRetryThrottler,
pub(crate) read_resume_policy: Arc<dyn ReadResumePolicy>,
pub(crate) resumable_upload_threshold: usize,
pub(crate) resumable_upload_buffer_size: usize,
pub(crate) idempotency: Option<bool>,
pub(crate) checksum: Checksum,
pub(crate) automatic_decompression: bool,
}
const MIB: usize = 1024 * 1024_usize;
const RESUMABLE_UPLOAD_THRESHOLD: usize = 16 * MIB;
const RESUMABLE_UPLOAD_TARGET_CHUNK: usize = 8 * MIB;
impl RequestOptions {
pub(crate) fn new() -> Self {
let retry_policy = Arc::new(crate::retry_policy::storage_default());
let backoff_policy = Arc::new(crate::backoff_policy::default());
let retry_throttler = Arc::new(Mutex::new(AdaptiveThrottler::default()));
let read_resume_policy = Arc::new(Recommended);
Self {
retry_policy,
backoff_policy,
retry_throttler,
read_resume_policy,
resumable_upload_threshold: RESUMABLE_UPLOAD_THRESHOLD,
resumable_upload_buffer_size: RESUMABLE_UPLOAD_TARGET_CHUNK,
idempotency: None,
checksum: Checksum {
crc32c: Some(Crc32c::default()),
md5_hash: None,
},
automatic_decompression: false,
}
}
}