Skip to content

Commit 0ae251d

Browse files
committed
initial commit
1 parent 76d60eb commit 0ae251d

4 files changed

Lines changed: 41 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Space-separated key-value pairs to override S3 request configuration per page mi
4747
- `ma=<num>` Maximum attempts
4848
- `ib=<ms>` Initial backoff duration
4949
- `mb=<ms>` Maximum backoff duration
50+
- `fps=<bool>` Force path-style addressing
5051

5152
#### Example Request
5253

src/object_store/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct RequestConfig {
1111
pub max_attempts: Option<u32>,
1212
pub initial_backoff: Option<Duration>,
1313
pub max_backoff: Option<Duration>,
14+
pub force_path_style: Option<bool>,
1415
}
1516

1617
impl RequestConfig {
@@ -23,6 +24,7 @@ impl RequestConfig {
2324
&& self.max_attempts.is_none()
2425
&& self.initial_backoff.is_none()
2526
&& self.max_backoff.is_none()
27+
&& self.force_path_style.is_none()
2628
}
2729

2830
fn has_timeout_overrides(&self) -> bool {

src/object_store/downloader.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ impl Downloader {
240240
{
241241
config_override = config_override.retry_config(retry_config);
242242
}
243+
if let Some(force_path_style) = req_config.force_path_style {
244+
config_override = config_override.force_path_style(force_path_style);
245+
}
243246

244247
request
245248
.customize()

src/service/routes.rs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ where
157157

158158
let mut config = Self::default();
159159

160+
let parse_duration = |v: &str| -> Result<Duration, Self::Rejection> {
161+
v.parse::<u64>().map(Duration::from_millis).map_err(|_| {
162+
(
163+
StatusCode::BAD_REQUEST,
164+
"Invalid duration value in C0-Config header",
165+
)
166+
})
167+
};
168+
160169
for pair in header_str.split_whitespace() {
161170
let Some((key, value)) = pair.split_once('=') else {
162171
return Err((
@@ -165,15 +174,6 @@ where
165174
));
166175
};
167176

168-
let parse_duration = |v: &str| -> Result<Duration, Self::Rejection> {
169-
v.parse::<u64>().map(Duration::from_millis).map_err(|_| {
170-
(
171-
StatusCode::BAD_REQUEST,
172-
"Invalid duration value in C0-Config header",
173-
)
174-
})
175-
};
176-
177177
match key {
178178
"ct" => config.connect_timeout = Some(parse_duration(value)?),
179179
"rt" => config.read_timeout = Some(parse_duration(value)?),
@@ -183,12 +183,20 @@ where
183183
config.max_attempts = Some(value.parse().map_err(|_| {
184184
(
185185
StatusCode::BAD_REQUEST,
186-
"Invalid max_attempts value in C0-Config hheader",
186+
"Invalid value for ma in C0-Config header",
187187
)
188188
})?);
189189
}
190190
"ib" => config.initial_backoff = Some(parse_duration(value)?),
191191
"mb" => config.max_backoff = Some(parse_duration(value)?),
192+
"fps" => {
193+
config.force_path_style = Some(value.parse().map_err(|_| {
194+
(
195+
StatusCode::BAD_REQUEST,
196+
"Invalid value for fps in C0-Config header",
197+
)
198+
})?);
199+
}
192200
_ => {} // Ignore unrecognized keys
193201
}
194202
}
@@ -542,6 +550,12 @@ mod tests {
542550
assert_eq!(config.max_attempts, Some(3));
543551
}
544552

553+
#[tokio::test]
554+
async fn test_c0_config_force_path_style() {
555+
let config = parse_c0_config("fps=true").await.unwrap();
556+
assert_eq!(config.force_path_style, Some(true));
557+
}
558+
545559
#[tokio::test]
546560
async fn test_c0_config_mixed_settings() {
547561
let config = parse_c0_config("ct=1000 ma=5 ib=10 oat=1500")
@@ -591,7 +605,17 @@ mod tests {
591605
assert!(result.is_err());
592606
assert_eq!(
593607
result.unwrap_err().1,
594-
"Invalid max_attempts value in C0-Config hheader"
608+
"Invalid value for ma in C0-Config header"
609+
);
610+
}
611+
612+
#[tokio::test]
613+
async fn test_c0_config_invalid_force_path_style() {
614+
let result = parse_c0_config("fps=1").await;
615+
assert!(result.is_err());
616+
assert_eq!(
617+
result.unwrap_err().1,
618+
"Invalid value for fps in C0-Config header"
595619
);
596620
}
597621

0 commit comments

Comments
 (0)