Added support for "Last-Modified" response header

This commit is contained in:
Pierre-Olivier Latour
2014-04-08 22:55:28 -07:00
parent 7339a7a2a6
commit f1a79ffd11
4 changed files with 13 additions and 2 deletions
+5
View File
@@ -74,6 +74,10 @@ static inline NSError* _MakePosixError(int code) {
return [self initWithFile:path byteRange:range isAttachment:NO];
}
static inline NSDate* _NSDateFromTimeSpec(const struct timespec* t) {
return [NSDate dateWithTimeIntervalSince1970:((NSTimeInterval)t->tv_sec + (NSTimeInterval)t->tv_nsec / 1000000000.0)];
}
- (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment {
struct stat info;
if (lstat([path fileSystemRepresentation], &info) || !(info.st_mode & S_IFREG)) {
@@ -121,6 +125,7 @@ static inline NSError* _MakePosixError(int code) {
self.contentType = GCDWebServerGetMimeTypeForExtension([path pathExtension]);
self.contentLength = (range.location != NSNotFound ? range.length : (NSUInteger)info.st_size);
self.lastModifiedDate = _NSDateFromTimeSpec(&info.st_mtimespec);
}
return self;
}