From e33854f3ebbe9749ae1f94fe4c6939ac1604a9c7 Mon Sep 17 00:00:00 2001 From: Jeff Oh Date: Thu, 12 Feb 2015 20:07:19 +0900 Subject: [PATCH] apply custom request header for every request type (ios) --- cocos/network/HttpClient-ios.mm | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/cocos/network/HttpClient-ios.mm b/cocos/network/HttpClient-ios.mm index 9a63e5e265..ef3aaa2c92 100644 --- a/cocos/network/HttpClient-ios.mm +++ b/cocos/network/HttpClient-ios.mm @@ -167,6 +167,23 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream //set request type [nsrequest setHTTPMethod:requestType]; + /* get custom header data (if set) */ + std::vector headers=request->getHeaders(); + if(!headers.empty()) + { + /* append custom headers one by one */ + for (std::vector::iterator it = headers.begin(); it != headers.end(); ++it) + { + unsigned long i = it->find(':', 0); + unsigned long length = it->size(); + std::string field = it->substr(0, i); + std::string value = it->substr(i+1, length-i); + NSString *headerField = [NSString stringWithUTF8String:field.c_str()]; + NSString *headerValue = [NSString stringWithUTF8String:value.c_str()]; + [nsrequest setValue:headerValue forHTTPHeaderField:headerField]; + } + } + //if request type is post or put,set header and data if([requestType isEqual: @"POST"] || [requestType isEqual: @"PUT"]) { @@ -174,22 +191,6 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream { [nsrequest setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"]; } - /* get custom header data (if set) */ - std::vector headers=request->getHeaders(); - if(!headers.empty()) - { - /* append custom headers one by one */ - for (std::vector::iterator it = headers.begin(); it != headers.end(); ++it) - { - unsigned long i = it->find(':', 0); - unsigned long length = it->size(); - std::string field = it->substr(0, i); - std::string value = it->substr(i+1, length-i); - NSString *headerField = [NSString stringWithUTF8String:field.c_str()]; - NSString *headerValue = [NSString stringWithUTF8String:value.c_str()]; - [nsrequest setValue:headerValue forHTTPHeaderField:headerField]; - } - } char* requestDataBuffer = request->getRequestData(); if (nullptr != requestDataBuffer && 0 != strlen(requestDataBuffer))