Skip to content

Commit 41c72d8

Browse files
authored
feat(core): Add correctness check for read with if_xxx headers (#5538)
1 parent 85c3803 commit 41c72d8

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

core/src/layers/correctness_check.rs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: &s
5656

5757
Error::new(
5858
ErrorKind::Unsupported,
59-
format!("service {scheme} doesn't support operation {op} with args {args}"),
59+
format!("The service {scheme} does not support the operation {op} with the arguments {args}. Please verify if the relevant flags have been enabled, or submit an issue if you believe this is incorrect."),
6060
)
6161
.with_operation(op)
6262
}
@@ -102,6 +102,34 @@ impl<A: Access> LayeredAccess for CorrectnessAccessor<A> {
102102
"version",
103103
));
104104
}
105+
if !capability.read_with_if_match && args.if_match().is_some() {
106+
return Err(new_unsupported_error(
107+
self.info.as_ref(),
108+
Operation::Read,
109+
"if_match",
110+
));
111+
}
112+
if !capability.read_with_if_none_match && args.if_none_match().is_some() {
113+
return Err(new_unsupported_error(
114+
self.info.as_ref(),
115+
Operation::Read,
116+
"if_none_match",
117+
));
118+
}
119+
if !capability.read_with_if_modified_since && args.if_modified_since().is_some() {
120+
return Err(new_unsupported_error(
121+
self.info.as_ref(),
122+
Operation::Read,
123+
"if_modified_since",
124+
));
125+
}
126+
if !capability.read_with_if_unmodified_since && args.if_unmodified_since().is_some() {
127+
return Err(new_unsupported_error(
128+
self.info.as_ref(),
129+
Operation::Read,
130+
"if_unmodified_since",
131+
));
132+
}
105133

106134
self.inner.read(path, args).await
107135
}
@@ -146,6 +174,34 @@ impl<A: Access> LayeredAccess for CorrectnessAccessor<A> {
146174
"version",
147175
));
148176
}
177+
if !capability.stat_with_if_match && args.if_match().is_some() {
178+
return Err(new_unsupported_error(
179+
self.info.as_ref(),
180+
Operation::Stat,
181+
"if_match",
182+
));
183+
}
184+
if !capability.stat_with_if_none_match && args.if_none_match().is_some() {
185+
return Err(new_unsupported_error(
186+
self.info.as_ref(),
187+
Operation::Stat,
188+
"if_none_match",
189+
));
190+
}
191+
if !capability.stat_with_if_modified_since && args.if_modified_since().is_some() {
192+
return Err(new_unsupported_error(
193+
self.info.as_ref(),
194+
Operation::Stat,
195+
"if_modified_since",
196+
));
197+
}
198+
if !capability.stat_with_if_unmodified_since && args.if_unmodified_since().is_some() {
199+
return Err(new_unsupported_error(
200+
self.info.as_ref(),
201+
Operation::Stat,
202+
"if_unmodified_since",
203+
));
204+
}
149205

150206
self.inner.stat(path, args).await
151207
}
@@ -410,7 +466,7 @@ mod tests {
410466
assert!(res.is_err());
411467
assert_eq!(
412468
res.unwrap_err().to_string(),
413-
"Unsupported (permanent) at write => service memory doesn't support operation write with args if_none_match"
469+
"Unsupported (permanent) at write => The service memory does not support the operation write with the arguments if_none_match. Please verify if the relevant flags have been enabled, or submit an issue if you believe this is incorrect."
414470
);
415471

416472
// Now try a wildcard if-none-match
@@ -421,8 +477,7 @@ mod tests {
421477
assert!(res.is_err());
422478
assert_eq!(
423479
res.unwrap_err().to_string(),
424-
"Unsupported (permanent) at write, context: { hint: use if_not_exists instead } => \
425-
service memory doesn't support operation write with args if_none_match"
480+
"Unsupported (permanent) at write, context: { hint: use if_not_exists instead } => The service memory does not support the operation write with the arguments if_none_match. Please verify if the relevant flags have been enabled, or submit an issue if you believe this is incorrect."
426481
);
427482

428483
let res = op

0 commit comments

Comments
 (0)