diff --git a/SVHTTPRequest/SVHTTPClient.h b/SVHTTPRequest/SVHTTPClient.h index 1f397f9..21437f5 100644 --- a/SVHTTPRequest/SVHTTPClient.h +++ b/SVHTTPRequest/SVHTTPClient.h @@ -46,4 +46,7 @@ typedef void (^SVHTTPRequestCompletionHandler)(id response, NSHTTPURLResponse *u @property (nonatomic, readwrite) NSURLRequestCachePolicy cachePolicy; @property (nonatomic, readwrite) NSUInteger timeoutInterval; +@property (nonatomic, readwrite) NSDictionary *headers; +@property (nonatomic, readwrite) BOOL dismissNSURLAuthenticationMethodServerTrust; + @end diff --git a/SVHTTPRequest/SVHTTPClient.m b/SVHTTPRequest/SVHTTPClient.m index c4b9e87..6663ed6 100644 --- a/SVHTTPRequest/SVHTTPClient.m +++ b/SVHTTPRequest/SVHTTPClient.m @@ -153,7 +153,9 @@ - (SVHTTPRequest*)queueRequest:(NSString*)path requestOperation.cachePolicy = self.cachePolicy; requestOperation.userAgent = self.userAgent; requestOperation.timeoutInterval = self.timeoutInterval; - + requestOperation.headers = self.headers; + requestOperation.dismissNSURLAuthenticationMethodServerTrust=_dismissNSURLAuthenticationMethodServerTrust; + [(id)requestOperation setClient:self]; [self.HTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *field, NSString *value, BOOL *stop) { diff --git a/SVHTTPRequest/SVHTTPRequest.h b/SVHTTPRequest/SVHTTPRequest.h index afe2a6b..07b8c9a 100644 --- a/SVHTTPRequest/SVHTTPRequest.h +++ b/SVHTTPRequest/SVHTTPRequest.h @@ -47,6 +47,8 @@ typedef NSUInteger SVHTTPRequestMethod; @property (nonatomic, readwrite) BOOL sendParametersAsJSON; @property (nonatomic, readwrite) NSURLRequestCachePolicy cachePolicy; @property (nonatomic, readwrite) NSUInteger timeoutInterval; +@property (nonatomic, readwrite) NSDictionary *headers; +@property (nonatomic, readwrite) BOOL dismissNSURLAuthenticationMethodServerTrust; @end diff --git a/SVHTTPRequest/SVHTTPRequest.m b/SVHTTPRequest/SVHTTPRequest.m index 54ca010..ffe540b 100644 --- a/SVHTTPRequest/SVHTTPRequest.m +++ b/SVHTTPRequest/SVHTTPRequest.m @@ -31,7 +31,7 @@ - (NSString*)encodedURLParameterString; static NSInteger SVHTTPRequestTaskCount = 0; static NSString *defaultUserAgent; -static NSTimeInterval SVHTTPRequestTimeoutInterval = 20; +static NSTimeInterval SVHTTPRequestTimeoutInterval = 100; @interface SVHTTPRequest () @@ -367,6 +367,10 @@ - (void)start { [self increaseSVHTTPRequestTaskCount]; }); + if (self.headers) { + [self.operationRequest setAllHTTPHeaderFields:self.headers]; + } + if(self.operationParameters) [self addParametersToRequest:self.operationParameters]; @@ -491,6 +495,20 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon self.operationURLResponse = (NSHTTPURLResponse*)response; } +- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if (_dismissNSURLAuthenticationMethodServerTrust) { + NSURLProtectionSpace * protectionSpace = [challenge protectionSpace]; + NSURLCredential* credentail = [NSURLCredential credentialForTrust:[protectionSpace serverTrust]]; + [[challenge sender] useCredential:credentail forAuthenticationChallenge:challenge]; + } + else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } +} + - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { dispatch_group_async(self.saveDataDispatchGroup, self.saveDataDispatchQueue, ^{ if(self.operationSavePath) {