From c6137914fa9012e7beb11eed54cde70a8235f0cd Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 4 Jan 2013 12:52:14 -0800 Subject: [PATCH] Adding AFHTTPClient -setDefaultCredential: --- AFNetworking/AFHTTPClient.h | 18 ++++++++++++++++-- AFNetworking/AFHTTPClient.m | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 68c6de8..7e73762 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -217,7 +217,8 @@ typedef enum { @param header The HTTP header to set a default value for @param value The value set as default for the specified header, or `nil */ -- (void)setDefaultHeader:(NSString *)header value:(NSString *)value; +- (void)setDefaultHeader:(NSString *)header + value:(NSString *)value; /** Sets the "Authorization" HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header. @@ -225,7 +226,8 @@ typedef enum { @param username The HTTP basic auth username @param password The HTTP basic auth password */ -- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password; +- (void)setAuthorizationHeaderWithUsername:(NSString *)username + password:(NSString *)password; /** Sets the "Authorization" HTTP header set in request objects made by the HTTP client to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header. @@ -234,11 +236,23 @@ typedef enum { */ - (void)setAuthorizationHeaderWithToken:(NSString *)token; + /** Clears any existing value for the "Authorization" HTTP header. */ - (void)clearAuthorizationHeader; +///------------------------------- +/// @name Managing URL Credentials +///------------------------------- + +/** + Set the default URL credential to be set for request operations. + + @param credential The URL credential + */ +- (void)setDefaultCredential:(NSURLCredential *)credential; + ///------------------------------- /// @name Creating Request Objects ///------------------------------- diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 3fec759..6ec823b 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -179,6 +179,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { @property (readwrite, nonatomic) NSURL *baseURL; @property (readwrite, nonatomic) NSMutableArray *registeredHTTPOperationClassNames; @property (readwrite, nonatomic) NSMutableDictionary *defaultHeaders; +@property (readwrite, nonatomic) NSURLCredential *defaultCredential; @property (readwrite, nonatomic) NSOperationQueue *operationQueue; #ifdef _SYSTEMCONFIGURATION_H @property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability; @@ -517,6 +518,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { } [operation setCompletionBlockWithSuccess:success failure:failure]; + + operation.credential = self.defaultCredential; return operation; }