diff --git a/cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp b/cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp index e1793ac..b26abad 100644 --- a/cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_xmlhttprequest.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "cocos/scripting/js-bindings/jswrapper/SeApi.h" #include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp" #include "cocos/network/HttpClient.h" @@ -350,11 +351,17 @@ void XMLHttpRequest::setReadyState(ReadyState readyState) } } +std::string to_lower(std::string s) { + for(char &c : s) + c = tolower(c); + return s; +} + void XMLHttpRequest::getHeader(const std::string& header) { // check for colon. - size_t found_header_field = header.find_first_of(":"); - +// size_t found_header_field = header.find_first_of(":"); + unsigned long found_header_field = header.find(":"); if (found_header_field != std::string::npos) { // Found a header field. @@ -375,9 +382,10 @@ void XMLHttpRequest::getHeader(const std::string& header) } // Transform field name to lower case as they are case-insensitive - std::transform(http_field.begin(), http_field.end(), http_field.begin(), ::tolower); + std::string lower_http_field = to_lower(http_field); +// std::transform(http_field.begin(), http_field.end(), http_field.begin(), ::tolower); - _httpHeader[http_field] = http_value; + _httpHeader[lower_http_field] = http_value; } else @@ -1042,7 +1050,7 @@ static bool XMLHttpRequest_setTimeout(se::State& s) unsigned long timeoutInMilliseconds = 0; bool ok = seval_to_ulong(args[0], &timeoutInMilliseconds); SE_PRECONDITION2(ok, false, "args[0] isn't a number"); - if (timeoutInMilliseconds < 50) + if (timeoutInMilliseconds < 50 && timeoutInMilliseconds != 0) { SE_LOGE("The timeout value (%lu ms) is too small, please note that timeout unit is milliseconds!", timeoutInMilliseconds); } @@ -1111,6 +1119,14 @@ static bool XMLHttpRequest_setResponseType(se::State& s) { xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB); } + else if (type == "ms-stream") + { + xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB); + } + else if (type == "moz-chunked-arraybuffer") + { + xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB); + } else { SE_PRECONDITION2(false, false, "The response type isn't supported!");