Skip to content

Commit

Permalink
Explicitly set caching policy and timeout (with a default of 10 secon…
Browse files Browse the repository at this point in the history
…ds if none is specified).
  • Loading branch information
paulyhedral committed Nov 12, 2014
1 parent dfdda36 commit 765de46
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions Snapper/Source/Shared/SNPBaseClientOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@property (nonatomic, copy) id (^serializationBlock)(id data, NSError** error);
@property (nonatomic, assign) Class serializationRootClass;
@property (nonatomic, assign) Class serializationArrayClass;
@property (nonatomic, assign) NSTimeInterval timeout;

// -- Initializers --

Expand Down
20 changes: 11 additions & 9 deletions Snapper/Source/Shared/SNPBaseClientOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ - (instancetype)initWithFinishBlock:(void (^)(SNPResponse* response))finishBlock
}

- (instancetype)initWithEndpoint:(NSURL*)endpoint
method:(NSString*)method
headers:(NSDictionary*)headers
parameters:(NSDictionary*)parameters
body:(NSData*)body
bodyType:(NSString*)bodyType
progressBlock:(void (^)(NSUInteger bytesWritten, NSUInteger totalBytesWritten, NSUInteger totalBytes))progressBlock
finishBlock:(void (^)(SNPResponse* response))finishBlock {
method:(NSString*)method
headers:(NSDictionary*)headers
parameters:(NSDictionary*)parameters
body:(NSData*)body
bodyType:(NSString*)bodyType
progressBlock:(void (^)(NSUInteger bytesWritten, NSUInteger totalBytesWritten, NSUInteger totalBytes))progressBlock
finishBlock:(void (^)(SNPResponse* response))finishBlock {

self = [self initWithFinishBlock:finishBlock];
if(self) {
Expand Down Expand Up @@ -106,7 +106,9 @@ - (void)main {
_endpoint = [NSURL URLWithString:urlString];
}

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_endpoint];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_endpoint
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:_timeout ?: 10];

// Provided headers
[_headers enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL* stop) {
Expand Down Expand Up @@ -359,7 +361,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection*)connection {
NSAssert(YES, @"Cannot deserialize response data; no deserialization method is set for this operation!");
}
}

if(_finishBlock) {
_finishBlock(response);
}
Expand Down
1 change: 1 addition & 0 deletions Snapper/Source/Shared/SNPBaseFileOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@property (nonatomic, copy) id (^serializationBlock)(id data, NSError** error);
@property (nonatomic, assign) Class serializationRootClass;
@property (nonatomic, assign) Class serializationArrayClass;
@property (nonatomic, assign) NSTimeInterval timeout;

// -- Initializers --
- (instancetype)initWithAccountId:(NSString*)accountId
Expand Down
6 changes: 4 additions & 2 deletions Snapper/Source/Shared/SNPBaseFileOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ - (void)main {
_endpoint = [NSURL URLWithString:urlString];
}

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_endpoint];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_endpoint
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:_timeout ?: 10];

// Provided headers
[_headers enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL* stop) {
Expand Down Expand Up @@ -334,7 +336,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection*)connection {
response.data = arrayOfData;
}
}

if(_finishBlock) {
_finishBlock(response);
}
Expand Down
1 change: 1 addition & 0 deletions Snapper/Source/Shared/SNPBaseImageFetchOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// -- Properties --
@property (nonatomic, retain) NSURL* imageURL;
@property (nonatomic, copy) void (^finishBlock)(id image, NSError* error);
@property (nonatomic, assign) NSTimeInterval timeout;

// -- Initializers --
- (instancetype)initWithImageURL:(NSURL*)imageURL
Expand Down
4 changes: 3 additions & 1 deletion Snapper/Source/Shared/SNPBaseImageFetchOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ - (void)main {

_receivedData = [NSMutableData new];

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_imageURL];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:_imageURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:_timeout ?: 10];

[request addValue:@"image/*"
forHTTPHeaderField:@"Accept"];
Expand Down
4 changes: 3 additions & 1 deletion Snapper/Source/Shared/SNPBaseUserTokenOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ - (void)main {
self.endpoint = [NSURL URLWithString:urlString];
}

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:self.endpoint];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:self.endpoint
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:self.timeout ?: 10];

// Provided headers
[self.headers enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL* stop) {
Expand Down

0 comments on commit 765de46

Please sign in to comment.