diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index bb3cd6c8e4..597701d0ba 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -951,11 +951,7 @@ void __JSDownloaderDelegator::startDownload() cocos2d::extension::Downloader::HeaderInfo info = _downloader->getHeader(_url); long contentSize = info.contentSize; - if (contentSize == -1 || info.responseCode >= 400) { - cocos2d::extension::Downloader::Error err; - onError(err); - } - else { + if (contentSize > 0 && info.responseCode < 400) { _size = contentSize / sizeof(unsigned char); _buffer = (unsigned char*)malloc(contentSize); _downloader->downloadToBufferSync(_url, _buffer, _size); diff --git a/extensions/assets-manager/Downloader.cpp b/extensions/assets-manager/Downloader.cpp index afa483440d..3187b19762 100644 --- a/extensions/assets-manager/Downloader.cpp +++ b/extensions/assets-manager/Downloader.cpp @@ -288,6 +288,7 @@ Downloader::HeaderInfo Downloader::prepareHeader(const std::string &srcUrl, void curl_easy_setopt(header, CURLOPT_URL, srcUrl.c_str()); curl_easy_setopt(header, CURLOPT_HEADER, 1); curl_easy_setopt(header, CURLOPT_NOBODY, 1); + curl_easy_setopt(header, CURLOPT_NOSIGNAL, 1); if (curl_easy_perform(header) == CURLE_OK) { char *url; @@ -296,16 +297,24 @@ Downloader::HeaderInfo Downloader::prepareHeader(const std::string &srcUrl, void curl_easy_getinfo(header, CURLINFO_CONTENT_TYPE, &contentType); curl_easy_getinfo(header, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &info.contentSize); curl_easy_getinfo(header, CURLINFO_RESPONSE_CODE, &info.responseCode); - info.url = url; - info.contentType = contentType; - info.valid = true; - if (_onHeader) + if (contentType == nullptr || info.contentSize == -1 || info.responseCode >= 400) { - _onHeader(srcUrl, info); + info.valid = false; + } + else + { + info.url = url; + info.contentType = contentType; + info.valid = true; } } - else + + if (info.valid && _onHeader) + { + _onHeader(srcUrl, info); + } + else if (!info.valid) { info.contentSize = -1; std::string msg = StringUtils::format("Can not get content size of file (%s) : Request header failed", srcUrl.c_str());