Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MugunthKumar/MKNetworkKit
Browse files Browse the repository at this point in the history
  • Loading branch information
MKSG-MugunthKumar committed Dec 5, 2011
2 parents 5c9882c + 1908284 commit 58bd4f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 9 additions & 1 deletion MKNetworkKit/MKNetworkEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@ - (void)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock
DLog(@"%@", error);
}];

[self enqueueOperation:op];
NSData *cachedData = [self cachedDataForOperation:op];

if(cachedData) {
[op setCachedData:cachedData];
}

if(!cachedData) { // If the cache is old when caching is implemented, this should come from cache
[self enqueueOperation:op];
}
}

#pragma -
Expand Down
26 changes: 14 additions & 12 deletions MKNetworkKit/MKNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ -(BOOL) isEqual:(id)object {

-(NSString*) uniqueIdentifier {

NSString *str = [NSString stringWithFormat:@"%@ %@",
self.request.HTTPMethod,
[self.request.URL absoluteString]];
NSString *str = [self curlCommandLineString];

if(self.username || self.password) {

Expand Down Expand Up @@ -422,14 +420,18 @@ - (id)initWithURLString:(NSString *)aURLString

NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding));

[self.request addValue:
[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset]
forHTTPHeaderField:@"Content-Type"];

[self.request addValue:[NSString stringWithFormat:@"%@, en-us",
[[NSLocale preferredLanguages] componentsJoinedByString:@", "]
] forHTTPHeaderField:@"Accept-Language"];

if (([method isEqualToString:@"POST"] ||
[method isEqualToString:@"PUT"]) && (params && [params count] > 0)) {

[self.request addValue:
[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset]
forHTTPHeaderField:@"Content-Type"];
}

self.state = MKNetworkOperationStateReady;
}

Expand All @@ -449,8 +451,10 @@ -(void) addHeaders:(NSDictionary*) headersDictionary {

-(NSString*) description {

NSMutableString *displayString = [[self curlCommandLineString] mutableCopy];

NSMutableString *displayString = [NSMutableString stringWithFormat:@"%@\nRequest\n-------\n%@",
[[NSDate date] descriptionWithLocale:[NSLocale currentLocale]],
[self curlCommandLineString]];

NSString *responseString = [self responseString];
if([responseString length] > 0) {
[displayString appendFormat:@"\n--------\nResponse\n--------\n%@\n", responseString];
Expand All @@ -461,9 +465,7 @@ -(NSString*) description {

-(NSString*) curlCommandLineString
{
__block NSMutableString *displayString = [NSMutableString stringWithFormat:@"%@\nRequest\n-------\ncurl -X %@",
[[NSDate date] descriptionWithLocale:[NSLocale currentLocale]],
self.request.HTTPMethod];
__block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -X %@", self.request.HTTPMethod];

if([self.filesToBePosted count] == 0 && [self.dataToBePosted count] == 0) {
[[self.request allHTTPHeaderFields] enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop)
Expand Down

0 comments on commit 58bd4f1

Please sign in to comment.