Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.
Open
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
29 changes: 16 additions & 13 deletions services/t-web/twisted-web/twisted-web
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def hotPatch255():
hotPatch255()


def movedTo(request, url):
def movedTo(request, url, encoding):
"""
Permanently redirect C{request} to C{url}.

Expand All @@ -71,21 +71,24 @@ def movedTo(request, url):
@param url: The new URL to which to redirect the request.
@type url: L{bytes}

@param encoding: The encoding of the response as a byte string.
@type encoding: L{bytes}

@return: The redirect HTML page.
@rtype: L{bytes}
"""
request.setResponseCode(http.MOVED_PERMANENTLY)
request.setHeader(b"location", url)
return ("""
return (b"""
<html>
<head>
<meta http-equiv=\"refresh\" content=\"0;URL=%(url)s\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<a href=\"%(url)s\">click here</a>
</body>
<head>
<meta charset="%(charset)s" http-equiv="refresh" content="0;URL=%(url)s">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="%(url)s">click here</a>
</body>
</html>
""" % {'url': url}).encode('ascii')
""" % {b'charset': encoding, b'url': url})


class RespondToHTTP01AndRedirectToHTTPS(resource.Resource):
Expand All @@ -108,16 +111,16 @@ class RespondToHTTP01AndRedirectToHTTPS(resource.Resource):
# Assume HTTPS is served over 443
httpsURL = URL(
scheme=u'https',
# I'm sure ASCII will be fine.
# I'm sure ASCII will be fine for hostnames.
host=request.getRequestHostname().decode('ascii'),
path=tuple(segment.decode('ascii')
path=tuple(segment.decode('utf-8')
for segment in request.prepath + request.postpath),

)
httpsLocation = httpsURL.asText().encode('ascii')
httpsLocation = httpsURL.asText().encode('utf-8')
if query:
httpsLocation += (b'?' + query)
return movedTo(request, httpsLocation)
return movedTo(request, httpsLocation, encoding=b'UTF-8')

def getChild(self, path, request):
return self
Expand Down