Skip to content

Commit 2266634

Browse files
committed
WebDAV: Return 304 NOT_MODIFIED on If-None-Match
1 parent 620ab2a commit 2266634

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

crates/dav-proto/src/schema/request.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
*/
66

77
use super::{
8+
Collation, MatchType,
89
property::{DavProperty, DavValue, LockScope, LockType},
910
response::Ace,
10-
Collation, MatchType,
1111
};
12-
use crate::Depth;
12+
use crate::{Condition, Depth};
1313
use calcard::{
1414
icalendar::{ICalendarComponentType, ICalendarParameterName, ICalendarProperty},
1515
vcard::{VCardParameterName, VCardProperty},
1616
};
1717
use types::{
18-
dead_property::{ArchivedDeadProperty, ArchivedDeadPropertyTag, DeadElementTag, DeadProperty},
1918
TimeRange,
19+
dead_property::{ArchivedDeadProperty, ArchivedDeadPropertyTag, DeadElementTag, DeadProperty},
2020
};
2121

2222
#[derive(Debug, Clone, PartialEq, Eq, Default)]
@@ -284,3 +284,12 @@ impl DavDeadProperty for ArchivedDeadProperty {
284284
}
285285
}
286286
}
287+
288+
impl Condition<'_> {
289+
pub fn is_none_match(&self) -> bool {
290+
match self {
291+
Condition::ETag { is_not, .. } | Condition::Exists { is_not } => *is_not,
292+
Condition::StateToken { .. } => false,
293+
}
294+
}
295+
}

crates/dav/src/common/lock.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,18 @@ impl LockRequestHandler for Server {
605605
return lock_response;
606606
}
607607

608-
Err(DavError::Code(StatusCode::PRECONDITION_FAILED))
608+
Err(DavError::Code(
609+
if matches!(method, DavMethod::GET | DavMethod::HEAD)
610+
&& headers
611+
.if_
612+
.iter()
613+
.any(|if_| if_.list.iter().any(|cond| cond.is_none_match()))
614+
{
615+
StatusCode::NOT_MODIFIED
616+
} else {
617+
StatusCode::PRECONDITION_FAILED
618+
},
619+
))
609620
}
610621
}
611622

0 commit comments

Comments
 (0)