Handle redirects that include a fragment

This commit is contained in:
Juhani Krekelä 2021-11-07 19:37:12 +02:00
parent 31fd864970
commit addf767d19
1 changed files with 3 additions and 1 deletions

View File

@ -140,6 +140,8 @@ class HtmlProcessor:
attribute = self.attribute.lower()
# TODO: handle more attributes
if tag == b'a' and attribute == b'href' or tag == b'img' and attribute == b'src':
# TODO: entities
# TODO: keep leading whitespace already in there
if self.value.strip().lower().startswith(b'https://'):
# Space is to keep the response size constant
return b' http://' + self.value.strip()[len(b'https://'):]
@ -441,7 +443,7 @@ def proxy(sock, host):
if destination_url.startswith(b'https://'):
destination_url = b'http://' + destination_url[len(b'https://'):]
if destination_url != url:
if destination_url.split(b'#')[0] != url:
rewritten_response.extend(b'Location: ')
rewritten_response.extend(destination_url)
rewritten_response.extend(b'\r\n')