Skip to content

Commit

Permalink
fix issues 233 (Cloud Files header issues) and 234 (leak in Cloud Fil…
Browse files Browse the repository at this point in the history
…es object request
  • Loading branch information
greenisus committed Aug 7, 2011
1 parent be2c003 commit a879b8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Classes/ASIHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"

// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.8.1-27 2011-08-07";
NSString *ASIHTTPRequestVersion = @"v1.8.1-28 2011-08-07";

static NSString *defaultUserAgent = nil;

Expand Down
2 changes: 2 additions & 0 deletions Classes/CloudFiles/ASICloudFilesCDNRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
// Response:
// X-CDN-Enabled: True
// X-CDN-URI: http://cdn.cloudfiles.mosso.com/c1234
// X-CDN-SSL-URI: https://cdn.ssl.cloudfiles.mosso.com/c1234
// X-CDN-TTL: 86400
+ (id)containerInfoRequest:(NSString *)containerName;
- (BOOL)cdnEnabled;
- (NSString *)cdnURI;
- (NSString *)cdnSSLURI;
- (NSUInteger)cdnTTL;


Expand Down
28 changes: 24 additions & 4 deletions Classes/CloudFiles/ASICloudFilesCDNRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,35 @@ + (id)containerInfoRequest:(NSString *)containerName {
}

- (BOOL)cdnEnabled {
return [[[self responseHeaders] objectForKey:@"X-Cdn-Enabled"] boolValue];
NSNumber *enabled = [[self responseHeaders] objectForKey:@"X-CDN-Enabled"];
if (!enabled) {
enabled = [[self responseHeaders] objectForKey:@"X-Cdn-Enabled"];
}
return [enabled boolValue];
}

- (NSString *)cdnURI {
return [[self responseHeaders] objectForKey:@"X-Cdn-Uri"];
NSString *uri = [[self responseHeaders] objectForKey:@"X-CDN-URI"];
if (!uri) {
uri = [[self responseHeaders] objectForKey:@"X-Cdn-Uri"];
}
return uri;
}

- (NSString *)cdnSSLURI {
NSString *uri = [[self responseHeaders] objectForKey:@"X-CDN-SSL-URI"];
if (!uri) {
uri = [[self responseHeaders] objectForKey:@"X-Cdn-Ssl-Uri"];
}
return uri;
}

- (NSUInteger)cdnTTL {
return [[[self responseHeaders] objectForKey:@"X-Ttl"] intValue];
NSNumber *ttl = [[self responseHeaders] objectForKey:@"X-TTL"];
if (!ttl) {
ttl = [[self responseHeaders] objectForKey:@"X-Ttl"];
}
return [ttl intValue];
}

#pragma mark -
Expand Down Expand Up @@ -130,7 +150,7 @@ + (id)postRequestWithContainer:(NSString *)containerName cdnEnabled:(BOOL)cdnEna
if (ttl > 0) {
[request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]];
}
[request addRequestHeader:@"X-Cdn-Enabled" value:cdnEnabled ? @"True" : @"False"];
[request addRequestHeader:@"X-CDN-Enabled" value:cdnEnabled ? @"True" : @"False"];
return request;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/CloudFiles/ASICloudFilesObjectRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ - (ASICloudFilesObject *)object {
object.bytes = [[[self responseHeaders] objectForKey:@"Content-Length"] intValue];
object.contentType = [[self responseHeaders] objectForKey:@"Content-Type"];
object.lastModified = [[self responseHeaders] objectForKey:@"Last-Modified"];
object.metadata = [[NSMutableDictionary alloc] init];
object.metadata = [NSMutableDictionary dictionary];

for (NSString *key in [[self responseHeaders] keyEnumerator]) {
NSRange metaRange = [key rangeOfString:@"X-Object-Meta-"];
Expand Down
8 changes: 7 additions & 1 deletion Classes/CloudFiles/ASICloudFilesRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ + (NSError *)authenticate
NSDictionary *responseHeaders = [request responseHeaders];
authToken = [responseHeaders objectForKey:@"X-Auth-Token"];
storageURL = [responseHeaders objectForKey:@"X-Storage-Url"];
cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"];
cdnManagementURL = [responseHeaders objectForKey:@"X-CDN-Management-Url"];

// there is a bug in the Cloud Files API for some older accounts that causes
// the CDN URL to come back in a slightly different header
if (!cdnManagementURL) {
cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"];
}
}
[accessDetailsLock unlock];
return [request error];
Expand Down

0 comments on commit a879b8e

Please sign in to comment.