Skip to content

Commit

Permalink
Merge branch '1.0RC2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Sep 14, 2012
2 parents 42fecdc + c1d3d84 commit c838016
Show file tree
Hide file tree
Showing 33 changed files with 241 additions and 579 deletions.
4 changes: 2 additions & 2 deletions AFNetworking.podspec
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'AFNetworking'
s.version = '0.10.1'
s.version = '1.0RC2'
s.license = 'MIT'
s.summary = 'A delightful iOS and OS X networking framework.'
s.homepage = 'https://github.com/AFNetworking/AFNetworking'
s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'}
s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '0.10.1' }
s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0RC2' }
s.source_files = 'AFNetworking'
s.framework = 'SystemConfiguration'
s.prefix_header_contents = "#import <SystemConfiguration/SystemConfiguration.h>"
Expand Down
4 changes: 2 additions & 2 deletions AFNetworking/AFHTTPClient.h
Expand Up @@ -99,7 +99,7 @@ typedef enum {
/**
The url used as the base for paths specified in methods such as `getPath:parameters:success:failure`
*/
@property (readonly, nonatomic, retain) NSURL *baseURL;
@property (readonly, nonatomic) NSURL *baseURL;

/**
The string encoding used in constructing url requests. This is `NSUTF8StringEncoding` by default.
Expand All @@ -116,7 +116,7 @@ typedef enum {
/**
The operation queue which manages operations enqueued by the HTTP client.
*/
@property (readonly, nonatomic, retain) NSOperationQueue *operationQueue;
@property (readonly, nonatomic) NSOperationQueue *operationQueue;

/**
The reachability status from the device to the current `baseURL` of the `AFHTTPClient`.
Expand Down
82 changes: 31 additions & 51 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -24,7 +24,6 @@

#import "AFHTTPClient.h"
#import "AFHTTPRequestOperation.h"
#import "AFJSONUtilities.h"

#import <Availability.h>

Expand Down Expand Up @@ -90,14 +89,14 @@ - (NSMutableURLRequest *)requestByFinalizingMultipartFormData;
output[idx + 3] = (i + 2) < length ? kAFBase64EncodingTable[(value >> 0) & 0x3F] : '=';
}

return [[[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding] autorelease];
return [[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding];
}

static NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString *string, NSStringEncoding encoding) {
// Escape characters that are legal in URIs, but have unintentional semantic significance when used in a query string parameter
static NSString * const kAFLegalCharactersToBeEscaped = @":/.?&=;+!@$()~";

return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease];
return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, (__bridge CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding));
}

#pragma mark -
Expand All @@ -120,19 +119,13 @@ - (id)initWithField:(id)field value:(id)value {
if (!self) {
return nil;
}

self.field = field;
self.value = value;

return self;
}

- (void)dealloc {
[_field release];
[_value release];
[super dealloc];
}

- (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding {
return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(self.field, stringEncoding), AFPercentEscapedQueryStringPairMemberFromStringWithEncoding([self.value description], stringEncoding)];
}
Expand Down Expand Up @@ -169,18 +162,18 @@ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
}];
} else {
[mutableQueryStringComponents addObject:[[[AFQueryStringPair alloc] initWithField:key value:value] autorelease]];
[mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
}

return mutableQueryStringComponents;
}

static NSString * AFJSONStringFromParameters(NSDictionary *parameters) {
NSError *error = nil;
NSData *JSONData = AFJSONEncode(parameters, &error);
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];;

if (!error) {
return [[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
} else {
return nil;
}
Expand All @@ -192,17 +185,17 @@ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding

NSData *propertyListData = [NSPropertyListSerialization dataWithPropertyList:parameters format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
if (!error) {
propertyListString = [[[NSString alloc] initWithData:propertyListData encoding:NSUTF8StringEncoding] autorelease];
propertyListString = [[NSString alloc] initWithData:propertyListData encoding:NSUTF8StringEncoding] ;
}

return propertyListString;
}

@interface AFHTTPClient ()
@property (readwrite, nonatomic, retain) NSURL *baseURL;
@property (readwrite, nonatomic, retain) NSMutableArray *registeredHTTPOperationClassNames;
@property (readwrite, nonatomic, retain) NSMutableDictionary *defaultHeaders;
@property (readwrite, nonatomic, retain) NSOperationQueue *operationQueue;
@property (readwrite, nonatomic) NSURL *baseURL;
@property (readwrite, nonatomic) NSMutableArray *registeredHTTPOperationClassNames;
@property (readwrite, nonatomic) NSMutableDictionary *defaultHeaders;
@property (readwrite, nonatomic) NSOperationQueue *operationQueue;
#ifdef _SYSTEMCONFIGURATION_H
@property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability;
@property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
Expand All @@ -229,7 +222,7 @@ @implementation AFHTTPClient
#endif

+ (AFHTTPClient *)clientWithBaseURL:(NSURL *)url {
return [[[self alloc] initWithBaseURL:url] autorelease];
return [[self alloc] initWithBaseURL:url];
}

- (id)initWithBaseURL:(NSURL *)url {
Expand Down Expand Up @@ -258,7 +251,7 @@ - (id)initWithBaseURL:(NSURL *)url {

#if __IPHONE_OS_VERSION_MIN_REQUIRED
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
[self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]];
[self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]];
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
[self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]];
#endif
Expand All @@ -268,7 +261,7 @@ - (id)initWithBaseURL:(NSURL *)url {
[self startMonitoringNetworkReachability];
#endif

self.operationQueue = [[[NSOperationQueue alloc] init] autorelease];
self.operationQueue = [[NSOperationQueue alloc] init];
[self.operationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];

return self;
Expand All @@ -277,15 +270,7 @@ - (id)initWithBaseURL:(NSURL *)url {
- (void)dealloc {
#ifdef _SYSTEMCONFIGURATION_H
[self stopMonitoringNetworkReachability];
[_networkReachabilityStatusBlock release];
#endif

[_baseURL release];
[_registeredHTTPOperationClassNames release];
[_defaultHeaders release];
[_operationQueue release];

[super dealloc];
}

- (NSString *)description {
Expand Down Expand Up @@ -325,7 +310,7 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork

static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
AFNetworkReachabilityStatusBlock block = (AFNetworkReachabilityStatusBlock)info;
AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info;
if (block) {
block(status);
}
Expand All @@ -334,11 +319,10 @@ static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused targ
}

static const void * AFNetworkReachabilityRetainCallback(const void *info) {
return [(AFNetworkReachabilityStatusBlock)info copy];
return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]);
}

static void AFNetworkReachabilityReleaseCallback(const void *info) {
[(AFNetworkReachabilityStatusBlock)info release];
}

- (void)startMonitoringNetworkReachability {
Expand All @@ -357,7 +341,7 @@ - (void)startMonitoringNetworkReachability {
}
};

SCNetworkReachabilityContext context = {0, callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes);

Expand Down Expand Up @@ -434,10 +418,11 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
parameters:(NSDictionary *)parameters
{
NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:method];
[request setAllHTTPHeaderFields:self.defaultHeaders];

[request setHTTPShouldHandleCookies:NO];

if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"]) {
[request setHTTPShouldUsePipelining:YES];
}
Expand All @@ -447,7 +432,7 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]];
[request setURL:url];
} else {
NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding));
NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding));
switch (self.parameterEncoding) {
case AFFormURLParameterEncoding:;
[request setValue:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
Expand All @@ -474,7 +459,7 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData>formData))block
{
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
__block AFMultipartFormData *formData = [[[AFMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding] autorelease];
__block AFMultipartFormData *formData = [[AFMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];

if (parameters) {
for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
Expand Down Expand Up @@ -508,12 +493,12 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlR
while (!operation && (className = [enumerator nextObject])) {
Class op_class = NSClassFromString(className);
if (op_class && [op_class canProcessRequest:urlRequest]) {
operation = [[(AFHTTPRequestOperation *)[op_class alloc] initWithRequest:urlRequest] autorelease];
operation = [(AFHTTPRequestOperation *)[op_class alloc] initWithRequest:urlRequest];
}
}

if (!operation) {
operation = [[[AFHTTPRequestOperation alloc] initWithRequest:urlRequest] autorelease];
operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
}

[operation setCompletionBlockWithSuccess:success failure:failure];
Expand Down Expand Up @@ -567,9 +552,9 @@ - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations
}];

for (AFHTTPRequestOperation *operation in operations) {
AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease];
AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy];
operation.completionBlock = ^{
dispatch_queue_t queue = operation.successCallbackQueue ? operation.successCallbackQueue : dispatch_get_main_queue();
dispatch_queue_t queue = operation.successCallbackQueue ?: dispatch_get_main_queue();
dispatch_group_async(dispatchGroup, queue, ^{
if (originalCompletionBlock) {
originalCompletionBlock();
Expand Down Expand Up @@ -683,8 +668,8 @@ - (id)copyWithZone:(NSZone *)zone {

HTTPClient.stringEncoding = self.stringEncoding;
HTTPClient.parameterEncoding = self.parameterEncoding;
HTTPClient.registeredHTTPOperationClassNames = [[self.registeredHTTPOperationClassNames copyWithZone:zone] autorelease];
HTTPClient.defaultHeaders = [[self.defaultHeaders copyWithZone:zone] autorelease];
HTTPClient.registeredHTTPOperationClassNames = [self.registeredHTTPOperationClassNames copyWithZone:zone];
HTTPClient.defaultHeaders = [self.defaultHeaders copyWithZone:zone];
#ifdef _SYSTEMCONFIGURATION_H
HTTPClient.networkReachabilityStatusBlock = self.networkReachabilityStatusBlock;
#endif
Expand Down Expand Up @@ -729,9 +714,9 @@ - (id)copyWithZone:(NSZone *)zone {
}

@interface AFMultipartFormData ()
@property (readwrite, nonatomic, retain) NSMutableURLRequest *request;
@property (readwrite, nonatomic) NSMutableURLRequest *request;
@property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
@property (readwrite, nonatomic, retain) NSOutputStream *outputStream;
@property (readwrite, nonatomic, strong) NSOutputStream *outputStream;
@property (readwrite, nonatomic, copy) NSString *temporaryFilePath;
@end

Expand Down Expand Up @@ -763,16 +748,11 @@ - (id)initWithURLRequest:(NSMutableURLRequest *)request
}

- (void)dealloc {
[_request release];

if (_outputStream) {
[_outputStream close];
[_outputStream release];
_outputStream = nil;
}

[_temporaryFilePath release];
[super dealloc];
}

- (NSMutableURLRequest *)requestByFinalizingMultipartFormData {
Expand Down Expand Up @@ -847,7 +827,7 @@ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
[userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey];
[userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey];
if (error != NULL) {
*error = [[[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease];
*error = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
}

return NO;
Expand Down
2 changes: 1 addition & 1 deletion AFNetworking/AFHTTPRequestOperation.h
Expand Up @@ -35,7 +35,7 @@
/**
The last HTTP response received by the operation's connection.
*/
@property (readonly, nonatomic, retain) NSHTTPURLResponse *response;
@property (readonly, nonatomic, strong) NSHTTPURLResponse *response;

///----------------------------------------------------------
/// @name Managing And Checking For Acceptable HTTP Responses
Expand Down

0 comments on commit c838016

Please sign in to comment.