From be022338158e4889c5dd6c67ab7c2a5ce2224034 Mon Sep 17 00:00:00 2001 From: huangshiwu Date: Thu, 8 Jan 2015 00:23:27 +0800 Subject: [PATCH 1/2] Fix XmlHttpRequestTest parsing error of response header on iOS platform --- cocos/network/HttpAsynConnection.h | 1 + cocos/network/HttpAsynConnection.m | 6 +++++- cocos/network/HttpClient-ios.mm | 1 + .../lua-bindings/manual/network/lua_xml_http_request.cpp | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cocos/network/HttpAsynConnection.h b/cocos/network/HttpAsynConnection.h index e4f8a7b94e..cd3b2cc78e 100644 --- a/cocos/network/HttpAsynConnection.h +++ b/cocos/network/HttpAsynConnection.h @@ -43,6 +43,7 @@ @property (readonly) NSInteger getDataTime; @property (readonly) NSInteger responseCode; +@property (readonly) NSString *statusString; @property (strong) NSError *responseError; diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index a365924437..5ddb717252 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -32,6 +32,7 @@ @synthesize responseData; @synthesize getDataTime; @synthesize responseCode; +@synthesize statusString; @synthesize responseError; @synthesize conn; @synthesize finish; @@ -73,7 +74,10 @@ responseHeader = [[httpResponse allHeaderFields] copy]; responseCode = httpResponse.statusCode; - if (responseCode != 200) + statusString = [[NSHTTPURLResponse localizedStringForStatusCode:responseCode] copy]; + if(responseCode == 200) + statusString = @"OK"; + if (responseCode/100 != 2) {// something went wrong, abort the whole thing [connection cancel]; diff --git a/cocos/network/HttpClient-ios.mm b/cocos/network/HttpClient-ios.mm index aacb6d821f..5be5271ffc 100644 --- a/cocos/network/HttpClient-ios.mm +++ b/cocos/network/HttpClient-ios.mm @@ -279,6 +279,7 @@ 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]; for (id key in httpAsynConn.responseHeader) { [header appendFormat:@"%@: %@\n", key, [httpAsynConn.responseHeader objectForKey:key]]; diff --git a/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp b/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp index 6a28bfec47..5d64c0390d 100644 --- a/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp +++ b/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp @@ -116,7 +116,7 @@ void LuaMinXmlHttpRequest::_gotHeader(string header) pch = strtok (NULL, " "); mystream << pch; - pch = strtok (NULL, " "); + pch = strtok (NULL, "\n"); mystream << " " << pch; _statusText = mystream.str(); From 108e4d2b411996f3b20cd4c53d08460c37a58a98 Mon Sep 17 00:00:00 2001 From: huangshiwu Date: Thu, 8 Jan 2015 10:12:45 +0800 Subject: [PATCH 2/2] Add comments and improve code readability for HttpAsynConnection.m --- cocos/network/HttpAsynConnection.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cocos/network/HttpAsynConnection.m b/cocos/network/HttpAsynConnection.m index 5ddb717252..cca536ea14 100755 --- a/cocos/network/HttpAsynConnection.m +++ b/cocos/network/HttpAsynConnection.m @@ -77,7 +77,17 @@ statusString = [[NSHTTPURLResponse localizedStringForStatusCode:responseCode] copy]; if(responseCode == 200) statusString = @"OK"; - if (responseCode/100 != 2) + + /*The individual values of the numeric status codes defined for HTTP/1.1 + | “200” ; OK + | “201” ; Created + | “202” ; Accepted + | “203” ; Non-Authoritative Information + | “204” ; No Content + | “205” ; Reset Content + | “206” ; Partial Content + */ + if (responseCode >= 200 && responseCode < 300) {// something went wrong, abort the whole thing [connection cancel];