Skip to content

Commit c613791

Browse files
committed
Adding AFHTTPClient -setDefaultCredential:
1 parent 1d243f7 commit c613791

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

AFNetworking/AFHTTPClient.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,17 @@ typedef enum {
217217
@param header The HTTP header to set a default value for
218218
@param value The value set as default for the specified header, or `nil
219219
*/
220-
- (void)setDefaultHeader:(NSString *)header value:(NSString *)value;
220+
- (void)setDefaultHeader:(NSString *)header
221+
value:(NSString *)value;
221222

222223
/**
223224
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.
224225
225226
@param username The HTTP basic auth username
226227
@param password The HTTP basic auth password
227228
*/
228-
- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password;
229+
- (void)setAuthorizationHeaderWithUsername:(NSString *)username
230+
password:(NSString *)password;
229231

230232
/**
231233
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 {
234236
*/
235237
- (void)setAuthorizationHeaderWithToken:(NSString *)token;
236238

239+
237240
/**
238241
Clears any existing value for the "Authorization" HTTP header.
239242
*/
240243
- (void)clearAuthorizationHeader;
241244

245+
///-------------------------------
246+
/// @name Managing URL Credentials
247+
///-------------------------------
248+
249+
/**
250+
Set the default URL credential to be set for request operations.
251+
252+
@param credential The URL credential
253+
*/
254+
- (void)setDefaultCredential:(NSURLCredential *)credential;
255+
242256
///-------------------------------
243257
/// @name Creating Request Objects
244258
///-------------------------------

AFNetworking/AFHTTPClient.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ @interface AFHTTPClient ()
179179
@property (readwrite, nonatomic) NSURL *baseURL;
180180
@property (readwrite, nonatomic) NSMutableArray *registeredHTTPOperationClassNames;
181181
@property (readwrite, nonatomic) NSMutableDictionary *defaultHeaders;
182+
@property (readwrite, nonatomic) NSURLCredential *defaultCredential;
182183
@property (readwrite, nonatomic) NSOperationQueue *operationQueue;
183184
#ifdef _SYSTEMCONFIGURATION_H
184185
@property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability;
@@ -517,6 +518,8 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlR
517518
}
518519

519520
[operation setCompletionBlockWithSuccess:success failure:failure];
521+
522+
operation.credential = self.defaultCredential;
520523

521524
return operation;
522525
}

0 commit comments

Comments
 (0)