--HG--
branch : compatibility-develop
This commit is contained in:
Riasan 2017-05-14 19:10:13 +02:00
commit cfc1951be6
2 changed files with 46 additions and 10 deletions

View file

@ -821,7 +821,7 @@ namespace NLGUI
{ {
public: public:
CDataDownload(const std::string &u, const std::string &d, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams()) CDataDownload(const std::string &u, const std::string &d, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams())
: data(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m) : data(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m), redirects(0)
{ {
if (t == ImgType) imgs.push_back(CDataImageDownload(i, style)); if (t == ImgType) imgs.push_back(CDataImageDownload(i, style));
} }
@ -833,6 +833,7 @@ namespace NLGUI
std::string luaScript; std::string luaScript;
std::string md5sum; std::string md5sum;
TDataType type; TDataType type;
uint32 redirects;
FILE *fp; FILE *fp;
std::vector<CDataImageDownload> imgs; std::vector<CDataImageDownload> imgs;
}; };

View file

@ -651,6 +651,40 @@ namespace NLGUI
string tmpfile = it->dest + ".tmp"; string tmpfile = it->dest + ".tmp";
if(res != CURLE_OK || r < 200 || r >= 300 || (!it->md5sum.empty() && (it->md5sum != getMD5(tmpfile).toString()))) if(res != CURLE_OK || r < 200 || r >= 300 || (!it->md5sum.empty() && (it->md5sum != getMD5(tmpfile).toString())))
{ {
if (it->redirects < DEFAULT_RYZOM_REDIRECT_LIMIT && ((r >= 301 && r <= 303) || r == 307 || r == 308))
{
std::string location(it->data->getLocationHeader());
if (!location.empty())
{
CUrlParser uri(location);
if (!uri.isAbsolute())
{
uri.inherit(it->url);
location = uri.toString();
}
it->url = location;
it->fp = NULL;
// release CCurlWWWData
delete it->data;
it->data = NULL;
it->redirects++;
#ifdef LOG_DL
nlwarning("Redirect '%s'", location.c_str());
#endif
// keep the request in queue
continue;
}
else
nlwarning("Redirected to empty url '%s'", it->url.c_str());
}
else
{
if (it->redirects >= DEFAULT_RYZOM_REDIRECT_LIMIT)
nlwarning("Redirect limit reached for '%s'", it->url.c_str());
NLMISC::CFile::deleteFile(tmpfile.c_str()); NLMISC::CFile::deleteFile(tmpfile.c_str());
// 304 Not Modified // 304 Not Modified
@ -664,6 +698,7 @@ namespace NLGUI
CHttpCache::getInstance()->store(it->dest, obj); CHttpCache::getInstance()->store(it->dest, obj);
} }
} }
}
else else
{ {
CHttpCacheObject obj; CHttpCacheObject obj;