euscan: better redirection handling
Fix dcc. Reported-by: jbergstroem Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
parent
a247472568
commit
c3dd96258b
33
euscan
33
euscan
@ -168,8 +168,8 @@ def gen_versions(components, level):
|
|||||||
|
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
def tryurl(fileurl, output, regex):
|
def tryurl(fileurl, output, template):
|
||||||
result = False
|
result = True
|
||||||
|
|
||||||
output.ebegin("Trying: " + fileurl)
|
output.ebegin("Trying: " + fileurl)
|
||||||
|
|
||||||
@ -180,25 +180,27 @@ def tryurl(fileurl, output, regex):
|
|||||||
headers = fp.info()
|
headers = fp.info()
|
||||||
|
|
||||||
if 'Content-disposition' in headers and basename not in headers['Content-disposition']:
|
if 'Content-disposition' in headers and basename not in headers['Content-disposition']:
|
||||||
result = False
|
result = None
|
||||||
elif 'Content-Length' in headers and headers['Content-Length'] == '0':
|
elif 'Content-Length' in headers and headers['Content-Length'] == '0':
|
||||||
result = False
|
result = None
|
||||||
elif 'text/html' in headers['Content-Type']:
|
elif 'text/html' in headers['Content-Type']:
|
||||||
result = False
|
result = None
|
||||||
elif fp.geturl() != fileurl:
|
elif fp.geturl() != fileurl:
|
||||||
|
regex = regex_from_template(template)
|
||||||
|
baseregex = regex_from_template(os.path.basename(template))
|
||||||
basename2 = os.path.basename(fp.geturl())
|
basename2 = os.path.basename(fp.geturl())
|
||||||
|
|
||||||
# Redirect to another (earlier?) version
|
# Redirect to another (earlier?) version
|
||||||
if basename != basename2 and re.match(regex, fp.geturl()):
|
if basename != basename2 and (re.match(regex, fp.geturl()) or re.match(baseregex, basename2)):
|
||||||
result = False
|
result = None
|
||||||
else:
|
|
||||||
result = True
|
|
||||||
else:
|
if result:
|
||||||
result = True
|
result = (fp.geturl(), fp.info())
|
||||||
except urllib2.URLError:
|
except urllib2.URLError:
|
||||||
result = False
|
result = None
|
||||||
except IOError:
|
except IOError:
|
||||||
result = False
|
result = None
|
||||||
|
|
||||||
output.eend(errno.ENOENT if not result else 0)
|
output.eend(errno.ENOENT if not result else 0)
|
||||||
|
|
||||||
@ -391,9 +393,10 @@ def brute_force(cpv, fileurl, options, output, limit=None):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
url = url_from_template(template, vstring)
|
url = url_from_template(template, vstring)
|
||||||
regex = regex_from_template(template)
|
|
||||||
|
|
||||||
if not tryurl(url, output, regex):
|
infos = tryurl(url, output, template)
|
||||||
|
|
||||||
|
if not infos:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result.append([url, vstring])
|
result.append([url, vstring])
|
||||||
|
Loading…
Reference in New Issue
Block a user