fix: only the path is returned when redirect location is a path

This commit is contained in:
草师傅 2025-07-31 18:34:22 +08:00
parent 535960b8ae
commit 8278ec5893

View file

@ -52,7 +52,12 @@ async def extend_short_urls(url):
if not url: if not url:
return url return url
if r.status in [301, 302, 304, 307, 308] and 'Location' in r.headers: if r.status in [301, 302, 304, 307, 308] and 'Location' in r.headers:
return r.headers['Location'] if 'http' in r.headers['Location']:
return r.headers['Location']
else:
# 如果 Location 头部没有 http 前缀,可能是相对路径
# 需要将其转换正确的链接
return urlparse(url)._replace(path=r.headers['Location']).geturl()
return url return url
def extract_tb_url_from_html(html_content): def extract_tb_url_from_html(html_content):