feat(server): normalize etags from webdav to properly check for file changes
This commit is contained in:
parent
3d93c96c31
commit
472106a0f6
|
|
@ -83,7 +83,13 @@ pub fn parse_propfind_response(xml_text: &str) -> Result<Vec<FileInfo>> {
|
||||||
resp.content_type = Some(text.trim().to_string());
|
resp.content_type = Some(text.trim().to_string());
|
||||||
}
|
}
|
||||||
"getetag" => {
|
"getetag" => {
|
||||||
resp.etag = Some(text.trim().to_string());
|
// Normalize ETag by removing quotes and weak ETag prefix
|
||||||
|
let etag = text.trim();
|
||||||
|
let normalized = etag
|
||||||
|
.trim_start_matches("W/")
|
||||||
|
.trim_matches('"')
|
||||||
|
.to_string();
|
||||||
|
resp.etag = Some(normalized);
|
||||||
}
|
}
|
||||||
"status" if in_propstat => {
|
"status" if in_propstat => {
|
||||||
// Check if status is 200 OK
|
// Check if status is 200 OK
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,26 @@ fn test_etag_change_detection() {
|
||||||
assert_eq!(normalized_etag, old_etag);
|
assert_eq!(normalized_etag, old_etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_etag_normalization() {
|
||||||
|
// Test various ETag formats that WebDAV servers might return
|
||||||
|
let test_cases = vec![
|
||||||
|
("abc123", "abc123"), // Plain ETag
|
||||||
|
("\"abc123\"", "abc123"), // Quoted ETag
|
||||||
|
("W/\"abc123\"", "abc123"), // Weak ETag
|
||||||
|
("\"abc-123-def\"", "abc-123-def"), // Quoted with dashes
|
||||||
|
("W/\"abc-123-def\"", "abc-123-def"), // Weak ETag with dashes
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in test_cases {
|
||||||
|
let normalized = input
|
||||||
|
.trim_start_matches("W/")
|
||||||
|
.trim_matches('"');
|
||||||
|
assert_eq!(normalized, expected,
|
||||||
|
"Failed to normalize ETag: {} -> expected {}", input, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_path_normalization() {
|
fn test_path_normalization() {
|
||||||
let test_paths = vec![
|
let test_paths = vec![
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue