Skip to content

Commit d78aa3b

Browse files
committed
Allow HEAD requests on collections
1 parent fcea9ca commit d78aa3b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

GCDWebDAVServer/GCDWebDAVServer.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ - (GCDWebServerResponse*)performGET:(GCDWebServerRequest*)request {
8888
if (![absolutePath hasPrefix:_uploadDirectory] || ![[NSFileManager defaultManager] fileExistsAtPath:absolutePath isDirectory:&isDirectory]) {
8989
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_NotFound message:@"\"%@\" does not exist", relativePath];
9090
}
91-
if (isDirectory) {
92-
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_BadRequest message:@"\"%@\" is not a file", relativePath];
91+
92+
NSString* itemName = [absolutePath lastPathComponent];
93+
if (([itemName hasPrefix:@"."] && !_showHidden) || (!isDirectory && ![self _checkFileExtension:itemName])) {
94+
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Downlading item name \"%@\" is not allowed", itemName];
9395
}
9496

95-
NSString* fileName = [absolutePath lastPathComponent];
96-
if (([fileName hasPrefix:@"."] && !_showHidden) || ![self _checkFileExtension:fileName]) {
97-
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Downlading file name \"%@\" is not allowed", fileName];
97+
// Because HEAD requests are mapped to GET ones, we need to handle directories but it's OK to return nothing per http://webdav.org/specs/rfc4918.html#rfc.section.9.4
98+
if (isDirectory) {
99+
return [GCDWebServerResponse response];
98100
}
99101

100102
if ([_delegate respondsToSelector:@selector(davServer:didDownloadFileAtPath:)]) {

0 commit comments

Comments
 (0)