Merge branch 'master' of github.com:pokeb/asi-http-request
Conflicts: Classes/ASIHTTPRequest.m
Showing
5 changed files
with
38 additions
and
8 deletions
| @@ -58,9 +58,11 @@ static NSLock *readLock = nil; | @@ -58,9 +58,11 @@ static NSLock *readLock = nil; | ||
| 58 | } | 58 | } |
| 59 | [request performThrottling]; | 59 | [request performThrottling]; |
| 60 | } | 60 | } |
| 61 | - [ASIHTTPRequest incrementBandwidthUsedInLastSecond:toRead]; | ||
| 62 | [readLock unlock]; | 61 | [readLock unlock]; |
| 63 | - return [stream read:buffer maxLength:toRead]; | 62 | + NSInteger rv = [stream read:buffer maxLength:toRead]; |
| 63 | + if (rv > 0) | ||
| 64 | + [ASIHTTPRequest incrementBandwidthUsedInLastSecond:rv]; | ||
| 65 | + return rv; | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | /* | 68 | /* |
| @@ -24,10 +24,12 @@ | @@ -24,10 +24,12 @@ | ||
| 24 | // Response: | 24 | // Response: |
| 25 | // X-CDN-Enabled: True | 25 | // X-CDN-Enabled: True |
| 26 | // X-CDN-URI: http://cdn.cloudfiles.mosso.com/c1234 | 26 | // X-CDN-URI: http://cdn.cloudfiles.mosso.com/c1234 |
| 27 | +// X-CDN-SSL-URI: https://cdn.ssl.cloudfiles.mosso.com/c1234 | ||
| 27 | // X-CDN-TTL: 86400 | 28 | // X-CDN-TTL: 86400 |
| 28 | + (id)containerInfoRequest:(NSString *)containerName; | 29 | + (id)containerInfoRequest:(NSString *)containerName; |
| 29 | - (BOOL)cdnEnabled; | 30 | - (BOOL)cdnEnabled; |
| 30 | - (NSString *)cdnURI; | 31 | - (NSString *)cdnURI; |
| 32 | +- (NSString *)cdnSSLURI; | ||
| 31 | - (NSUInteger)cdnTTL; | 33 | - (NSUInteger)cdnTTL; |
| 32 | 34 | ||
| 33 | 35 |
| @@ -38,15 +38,35 @@ | @@ -38,15 +38,35 @@ | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - (BOOL)cdnEnabled { | 40 | - (BOOL)cdnEnabled { |
| 41 | - return [[[self responseHeaders] objectForKey:@"X-Cdn-Enabled"] boolValue]; | 41 | + NSNumber *enabled = [[self responseHeaders] objectForKey:@"X-CDN-Enabled"]; |
| 42 | + if (!enabled) { | ||
| 43 | + enabled = [[self responseHeaders] objectForKey:@"X-Cdn-Enabled"]; | ||
| 44 | + } | ||
| 45 | + return [enabled boolValue]; | ||
| 42 | } | 46 | } |
| 43 | 47 | ||
| 44 | - (NSString *)cdnURI { | 48 | - (NSString *)cdnURI { |
| 45 | - return [[self responseHeaders] objectForKey:@"X-Cdn-Uri"]; | 49 | + NSString *uri = [[self responseHeaders] objectForKey:@"X-CDN-URI"]; |
| 50 | + if (!uri) { | ||
| 51 | + uri = [[self responseHeaders] objectForKey:@"X-Cdn-Uri"]; | ||
| 52 | + } | ||
| 53 | + return uri; | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +- (NSString *)cdnSSLURI { | ||
| 57 | + NSString *uri = [[self responseHeaders] objectForKey:@"X-CDN-SSL-URI"]; | ||
| 58 | + if (!uri) { | ||
| 59 | + uri = [[self responseHeaders] objectForKey:@"X-Cdn-Ssl-Uri"]; | ||
| 60 | + } | ||
| 61 | + return uri; | ||
| 46 | } | 62 | } |
| 47 | 63 | ||
| 48 | - (NSUInteger)cdnTTL { | 64 | - (NSUInteger)cdnTTL { |
| 49 | - return [[[self responseHeaders] objectForKey:@"X-Ttl"] intValue]; | 65 | + NSNumber *ttl = [[self responseHeaders] objectForKey:@"X-TTL"]; |
| 66 | + if (!ttl) { | ||
| 67 | + ttl = [[self responseHeaders] objectForKey:@"X-Ttl"]; | ||
| 68 | + } | ||
| 69 | + return [ttl intValue]; | ||
| 50 | } | 70 | } |
| 51 | 71 | ||
| 52 | #pragma mark - | 72 | #pragma mark - |
| @@ -130,7 +150,7 @@ | @@ -130,7 +150,7 @@ | ||
| 130 | if (ttl > 0) { | 150 | if (ttl > 0) { |
| 131 | [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]]; | 151 | [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]]; |
| 132 | } | 152 | } |
| 133 | - [request addRequestHeader:@"X-Cdn-Enabled" value:cdnEnabled ? @"True" : @"False"]; | 153 | + [request addRequestHeader:@"X-CDN-Enabled" value:cdnEnabled ? @"True" : @"False"]; |
| 134 | return request; | 154 | return request; |
| 135 | } | 155 | } |
| 136 | 156 |
| @@ -130,7 +130,7 @@ | @@ -130,7 +130,7 @@ | ||
| 130 | object.bytes = [[[self responseHeaders] objectForKey:@"Content-Length"] intValue]; | 130 | object.bytes = [[[self responseHeaders] objectForKey:@"Content-Length"] intValue]; |
| 131 | object.contentType = [[self responseHeaders] objectForKey:@"Content-Type"]; | 131 | object.contentType = [[self responseHeaders] objectForKey:@"Content-Type"]; |
| 132 | object.lastModified = [[self responseHeaders] objectForKey:@"Last-Modified"]; | 132 | object.lastModified = [[self responseHeaders] objectForKey:@"Last-Modified"]; |
| 133 | - object.metadata = [[NSMutableDictionary alloc] init]; | 133 | + object.metadata = [NSMutableDictionary dictionary]; |
| 134 | 134 | ||
| 135 | for (NSString *key in [[self responseHeaders] keyEnumerator]) { | 135 | for (NSString *key in [[self responseHeaders] keyEnumerator]) { |
| 136 | NSRange metaRange = [key rangeOfString:@"X-Object-Meta-"]; | 136 | NSRange metaRange = [key rangeOfString:@"X-Object-Meta-"]; |
| @@ -69,7 +69,13 @@ static NSRecursiveLock *accessDetailsLock = nil; | @@ -69,7 +69,13 @@ static NSRecursiveLock *accessDetailsLock = nil; | ||
| 69 | NSDictionary *responseHeaders = [request responseHeaders]; | 69 | NSDictionary *responseHeaders = [request responseHeaders]; |
| 70 | authToken = [responseHeaders objectForKey:@"X-Auth-Token"]; | 70 | authToken = [responseHeaders objectForKey:@"X-Auth-Token"]; |
| 71 | storageURL = [responseHeaders objectForKey:@"X-Storage-Url"]; | 71 | storageURL = [responseHeaders objectForKey:@"X-Storage-Url"]; |
| 72 | - cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"]; | 72 | + cdnManagementURL = [responseHeaders objectForKey:@"X-CDN-Management-Url"]; |
| 73 | + | ||
| 74 | + // there is a bug in the Cloud Files API for some older accounts that causes | ||
| 75 | + // the CDN URL to come back in a slightly different header | ||
| 76 | + if (!cdnManagementURL) { | ||
| 77 | + cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"]; | ||
| 78 | + } | ||
| 73 | } | 79 | } |
| 74 | [accessDetailsLock unlock]; | 80 | [accessDetailsLock unlock]; |
| 75 | return [request error]; | 81 | return [request error]; |
-
Please register or login to post a comment