Improved handling of symbolic links in -addGETHandlerForBasePath:directoryPath:indexFilename:cacheAge:allowRangeRequests:

This commit is contained in:
Pierre-Olivier Latour
2014-09-19 08:19:49 -07:00
parent 00b5ec87ba
commit f1e9f1a37c
+6 -5
View File
@@ -882,17 +882,18 @@ static inline NSString* _EncodeBase64(NSString* string) {
GCDWebServerResponse* response = nil; GCDWebServerResponse* response = nil;
NSString* filePath = [directoryPath stringByAppendingPathComponent:[request.path substringFromIndex:basePath.length]]; NSString* filePath = [directoryPath stringByAppendingPathComponent:[request.path substringFromIndex:basePath.length]];
BOOL isDirectory; NSString* fileType = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL] fileType];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory]) { if (fileType) {
if (isDirectory) { if ([fileType isEqualToString:NSFileTypeDirectory]) {
if (indexFilename) { if (indexFilename) {
NSString* indexPath = [filePath stringByAppendingPathComponent:indexFilename]; NSString* indexPath = [filePath stringByAppendingPathComponent:indexFilename];
if ([[NSFileManager defaultManager] fileExistsAtPath:indexPath isDirectory:&isDirectory] && !isDirectory) { NSString* indexType = [[[NSFileManager defaultManager] attributesOfItemAtPath:indexPath error:NULL] fileType];
if ([indexType isEqualToString:NSFileTypeRegular]) {
return [GCDWebServerFileResponse responseWithFile:indexPath]; return [GCDWebServerFileResponse responseWithFile:indexPath];
} }
} }
response = [server _responseWithContentsOfDirectory:filePath]; response = [server _responseWithContentsOfDirectory:filePath];
} else { } else if ([fileType isEqualToString:NSFileTypeRegular]) {
if (allowRangeRequests) { if (allowRangeRequests) {
response = [GCDWebServerFileResponse responseWithFile:filePath byteRange:request.byteRange]; response = [GCDWebServerFileResponse responseWithFile:filePath byteRange:request.byteRange];
[response setValue:@"bytes" forAdditionalHeader:@"Accept-Ranges"]; [response setValue:@"bytes" forAdditionalHeader:@"Accept-Ranges"];