diff --git a/net/net/src/TWebFile.cxx b/net/net/src/TWebFile.cxx index 9e459d318d66b..065642a32bea4 100644 --- a/net/net/src/TWebFile.cxx +++ b/net/net/src/TWebFile.cxx @@ -660,12 +660,19 @@ Int_t TWebFile::GetFromWeb10(char *buf, Int_t len, const TString &msg) Int_t n, ret = 0, nranges = 0, ltot = 0, redirect = 0; TString boundary, boundaryEnd; Long64_t first = -1, last = -1, tot; + TString redir; while ((n = GetLine(fSocket, line, sizeof(line))) >= 0) { if (n == 0) { if (ret < 0) return ret; if (redirect) { + if (redir.IsNull()) { + // Some sites (s3.amazonaws.com) do not return a Location field on 301 + Error("GetFromWeb10", "error - permanent redirect (301) without location from host %s", fUrl.GetHost()); + return -1; + } + ws.ReOpen(); // set message to reflect the redirectLocation and add bytes field TString msg_1 = fMsgReadBuffer10; @@ -775,7 +782,7 @@ Int_t TWebFile::GetFromWeb10(char *buf, Int_t len, const TString &msg) #endif if (fSize == -1) fSize = tot; } else if (res.BeginsWith("Location:") && redirect) { - TString redir = res(10, 1000); + redir = res(10, 1000); if (redirect == 2) // temp redirect SetMsgReadBuffer10(redir, kTRUE); else // permanent redirect @@ -783,6 +790,11 @@ Int_t TWebFile::GetFromWeb10(char *buf, Int_t len, const TString &msg) } } + if (redirect && redir.IsNull()) { + ret = -1; + Error("GetFromWeb10", "error - permanent redirect (301) without location from host %s", fUrl.GetHost()); + } + if (n == -1 && fHTTP11) { if (gDebug > 0) Info("GetFromWeb10", "HTTP/1.1 socket closed, reopen"); @@ -945,6 +957,7 @@ Int_t TWebFile::GetHead() char line[8192]; Int_t n, ret = 0, redirect = 0; + TString redir; while ((n = GetLine(s, line, sizeof(line))) >= 0) { if (n == 0) { @@ -958,8 +971,14 @@ Int_t TWebFile::GetHead() } if (ret < 0) return ret; - if (redirect) - return GetHead(); + if (redirect) { + if (redir.IsNull()) { + // Some sites (s3.amazonaws.com) do not return a Location field on 301 + Error("GetHead", "error - permanent redirect (301) without location from host %s", fUrl.GetHost()); + return -1; + } + return GetHead(); + } return 0; } @@ -1015,7 +1034,7 @@ Int_t TWebFile::GetHead() TString slen = res(16, 1000); fSize = slen.Atoll(); } else if (res.BeginsWith("Location:") && redirect) { - TString redir = res(10, 1000); + redir = res(10, 1000); if (redirect == 2) // temp redirect SetMsgReadBuffer10(redir, kTRUE); else // permanent redirect