diff --git a/cocos/network/HttpAsynConnection.h b/cocos/network/HttpAsynConnection.h index cd3b2cc78e..53e65dc32d 100644 --- a/cocos/network/HttpAsynConnection.h +++ b/cocos/network/HttpAsynConnection.h @@ -36,7 +36,7 @@ @property (strong) NSString *sslFile; -@property (strong) NSDictionary *responseHeader; +@property (copy) NSDictionary *responseHeader; @property (strong) NSMutableData *responseData; diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index 63892ff282..1be9ff2fdd 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -24,6 +24,12 @@ #import "HttpAsynConnection.h" +@interface HttpAsynConnection () + +@property (readwrite) NSString *statusString; + +@end + @implementation HttpAsynConnection @synthesize srcURL; @@ -38,19 +44,33 @@ @synthesize finish; @synthesize runLoop; +- (void)dealloc +{ + [srcURL release]; + [sslFile release]; + [responseHeader release]; + [responseData release]; + [statusString release]; + [responseError release]; + [conn release]; + [runLoop release]; + + [super dealloc]; +} + - (void) startRequest:(NSURLRequest *)request { NSLog(@"Starting to load %@", srcURL); finish = false; - responseData = [NSMutableData new]; + self.responseData = [NSMutableData data]; getDataTime = 0; - responseError = nil; + self.responseError = nil; // create the connection with the target request and this class as the delegate - self.conn = [[NSURLConnection alloc] initWithRequest:request - delegate:self - startImmediately:NO]; + self.conn = [[[NSURLConnection alloc] initWithRequest:request + delegate:self + startImmediately:NO] autorelease]; [self.conn scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; @@ -71,12 +91,12 @@ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; //NSLog(@"All headers = %@", [httpResponse allHeaderFields]); - responseHeader = [[httpResponse allHeaderFields] copy]; + self.responseHeader = [httpResponse allHeaderFields]; responseCode = httpResponse.statusCode; - statusString = [[NSHTTPURLResponse localizedStringForStatusCode:responseCode] copy]; + self.statusString = [NSHTTPURLResponse localizedStringForStatusCode:responseCode]; if(responseCode == 200) - statusString = @"OK"; + self.statusString = @"OK"; /*The individual values of the numeric status codes defined for HTTP/1.1 | “200” ; OK @@ -118,7 +138,7 @@ didFailWithError:(NSError *)error { //NSLog(@"Load failed with error %@", [error localizedDescription]); - responseError = [error copy]; + self.responseError = error; finish = true; } diff --git a/cocos/network/HttpClient-ios.mm b/cocos/network/HttpClient-ios.mm index 5b7dd05e8d..0dc80bf21b 100644 --- a/cocos/network/HttpClient-ios.mm +++ b/cocos/network/HttpClient-ios.mm @@ -77,8 +77,8 @@ void HttpClient::networkThread() { auto scheduler = Director::getInstance()->getScheduler(); - while (true) - { + while (true) @autoreleasepool { + HttpRequest *request; // step 1: send http request if the requestQueue isn't empty @@ -224,16 +224,16 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream } } - HttpAsynConnection *httpAsynConn = [HttpAsynConnection new]; + HttpAsynConnection *httpAsynConn = [[HttpAsynConnection new] autorelease]; httpAsynConn.srcURL = urlstring; httpAsynConn.sslFile = nil; - NSString *sslFile = nil; + if(!s_sslCaFilename.empty()) { long len = s_sslCaFilename.length(); long pos = s_sslCaFilename.rfind('.', len-1); - [sslFile initWithUTF8String:s_sslCaFilename.substr(0, pos-1).c_str()]; - httpAsynConn.sslFile = sslFile; + + httpAsynConn.sslFile = [NSString stringWithUTF8String:s_sslCaFilename.substr(0, pos-1).c_str()]; } [httpAsynConn startRequest:nsrequest]; @@ -281,8 +281,8 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream } //handle response header - NSMutableString *header = [NSMutableString new]; - [header appendFormat:@"HTTP/1.1 %ld %@\n", httpAsynConn.responseCode, httpAsynConn.statusString]; + NSMutableString *header = [NSMutableString string]; + [header appendFormat:@"HTTP/1.1 %ld %@\n", (long)httpAsynConn.responseCode, httpAsynConn.statusString]; for (id key in httpAsynConn.responseHeader) { [header appendFormat:@"%@: %@\n", key, [httpAsynConn.responseHeader objectForKey:key]];