Added -hasByteRange API

This commit is contained in:
Pierre-Olivier Latour 2014-04-07 19:29:04 -07:00
parent c51f9ad7d9
commit fb08e77c0c
4 changed files with 10 additions and 1 deletions

View File

@ -81,7 +81,7 @@ static inline NSError* _MakePosixError(int code) {
ARC_RELEASE(self);
return nil;
}
if ((range.location != NSNotFound) || (range.length > 0)) {
if (GCDWebServerIsValidByteRange(range)) {
if (range.location != NSNotFound) {
range.location = MIN(range.location, (NSUInteger)info.st_size);
range.length = MIN(range.length, (NSUInteger)info.st_size - range.location);

View File

@ -103,6 +103,10 @@ extern void GCDLogMessage(long level, NSString* format, ...) NS_FORMAT_FUNCTION(
#define kGCDWebServerGCDQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define kGCDWebServerErrorDomain @"GCDWebServerErrorDomain"
static inline BOOL GCDWebServerIsValidByteRange(NSRange range) {
return ((range.location != NSNotFound) || (range.length > 0));
}
extern NSString* GCDWebServerExtractHeaderParameter(NSString* header, NSString* attribute);
extern NSStringEncoding GCDWebServerStringEncodingFromCharset(NSString* charset);

View File

@ -44,4 +44,5 @@
@property(nonatomic, readonly) NSRange byteRange; // Automatically parsed from headers ([NSNotFound, 0] if request has no "Range" header, [offset, length] for byte range from beginning or [NSNotFound, -bytes] from end)
- (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query;
- (BOOL)hasBody; // Convenience method
- (BOOL)hasByteRange; // Convenience method that checks "byteRange"
@end

View File

@ -237,6 +237,10 @@
return _type ? YES : NO;
}
- (BOOL)hasByteRange {
return GCDWebServerIsValidByteRange(_range);
}
- (BOOL)open:(NSError**)error {
return YES;
}