forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python 3: port tests in content-dpr, mimesniff and upgrade-insecure-r… (
- Loading branch information
Showing
2 changed files
with
20 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
from wptserve.utils import isomorphic_decode | ||
|
||
def main(request, response): | ||
""" | ||
Simple handler that sets a response header based on which client hint | ||
request headers were received. | ||
""" | ||
|
||
response.headers.append("Access-Control-Allow-Origin", "*") | ||
response.headers.append(b"Access-Control-Allow-Origin", b"*") | ||
values = request.GET | ||
name = values.first('name') | ||
type = values.first('mimeType') | ||
dpr = values.first('dpr') | ||
name = values.first(b'name') | ||
type = values.first(b'mimeType') | ||
dpr = values.first(b'dpr') | ||
double = None | ||
if 'double' in values: | ||
double = values.first('double') | ||
image_path = request.doc_root + "/".join(request.url_parts[2].split("/")[:-1]) + "/" + name | ||
if b'double' in values: | ||
double = values.first(b'double') | ||
image_path = request.doc_root + u"/".join(request.url_parts[2].split(u"/")[:-1]) + u"/" + isomorphic_decode(name) | ||
f = open(image_path, "rb") | ||
buff = f.read() | ||
f.close() | ||
response.headers.set("Content-Type", type) | ||
response.headers.set("Content-DPR", dpr) | ||
response.headers.set(b"Content-Type", type) | ||
response.headers.set(b"Content-DPR", dpr) | ||
if double: | ||
response.headers.append("Content-DPR", double) | ||
response.headers.set("Content-Length", len(buff)) | ||
response.headers.append(b"Content-DPR", double) | ||
response.headers.set(b"Content-Length", len(buff)) | ||
response.content = buff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
from wptserve.utils import isomorphic_encode | ||
|
||
def main(request, response): | ||
content = "<meta charset=utf-8>\n<script>document.write(document.characterSet)</script>" | ||
content = b"<meta charset=utf-8>\n<script>document.write(document.characterSet)</script>" | ||
|
||
# This uses the following rather than | ||
# response.headers.set("Content-Type", request.GET.first("type")); | ||
# response.content = content | ||
# to work around https://github.com/web-platform-tests/wpt/issues/8372. | ||
|
||
response.add_required_headers = False | ||
output = "HTTP/1.1 200 OK\r\n" | ||
output += "Content-Length: " + str(len(content)) + "\r\n" | ||
output += "Content-Type: " + request.GET.first("type") + "\r\n" | ||
output += "\r\n" | ||
output = b"HTTP/1.1 200 OK\r\n" | ||
output += b"Content-Length: " + isomorphic_encode(str(len(content))) + b"\r\n" | ||
output += b"Content-Type: " + request.GET.first(b"type") + b"\r\n" | ||
output += b"\r\n" | ||
output += content | ||
response.writer.write(output) | ||
response.close_connection = True |