Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated WebDAV support to pass OmniPresence's conformance tests #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Extensions/WebDAV/DAVResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
// 9.8 COPY Method
// 9.9 MOVE Method
if ([method isEqualToString:@"MOVE"] || [method isEqualToString:@"COPY"]) {
if ([method isEqualToString:@"COPY"] && ![[headers objectForKey:@"Depth"] isEqualToString:@"infinity"]) {
HTTPLogError(@"Unsupported DAV depth \"%@\"", [headers objectForKey:@"Depth"]);
return nil;
if ([method isEqualToString:@"COPY"]) {
NSString *depth = [headers objectForKey:@"Depth"];
if (depth != nil && ![depth isEqualToString:@"infinity"]) { // The COPY method on a collection without a Depth header MUST act as if a Depth header with value "infinity" was included
HTTPLogError(@"Unsupported DAV depth \"%@\"", [headers objectForKey:@"Depth"]);
return nil;
}
}

NSString* sourcePath = [rootPath stringByAppendingPathComponent:resourcePath];
Expand All @@ -200,7 +203,7 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
}
NSString* destinationPath = [rootPath stringByAppendingPathComponent:
[[destination substringFromIndex:(range.location + range.length)] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (![destinationPath hasPrefix:rootPath] || [[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
if (![destinationPath hasPrefix:rootPath]) {
return nil;
}

Expand All @@ -210,10 +213,14 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
_status = 409;
} else {
BOOL existing = [[NSFileManager defaultManager] fileExistsAtPath:destinationPath];
if (existing && [[headers objectForKey:@"Overwrite"] isEqualToString:@"F"]) {
BOOL shouldNotOverwrite = [[headers objectForKey:@"Overwrite"] isEqualToString:@"F"];
if (existing && shouldNotOverwrite) {
HTTPLogError(@"Pre-existing destination path \"%@\"", destinationPath);
_status = 412;
} else {
if (existing && !shouldNotOverwrite) {
[[NSFileManager defaultManager] removeItemAtPath:destinationPath error:NULL];
}
if ([method isEqualToString:@"COPY"]) {
if ([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:NULL]) {
_status = existing ? 204 : 201;
Expand Down