Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions net/net/src/TWebFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -775,14 +782,19 @@ 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
SetMsgReadBuffer10(redir, kFALSE);
}
}

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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down