summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/common/large.py
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/common/large.py
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/common/large.py')
-rw-r--r--testing/web-platform/tests/common/large.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/testing/web-platform/tests/common/large.py b/testing/web-platform/tests/common/large.py
new file mode 100644
index 000000000..0db4e4bbd
--- /dev/null
+++ b/testing/web-platform/tests/common/large.py
@@ -0,0 +1,45 @@
+def main(request, response):
+ """Code for generating large responses where the actual response data
+ isn't very important.
+
+ Two request parameters:
+ size (required): An integer number of bytes (no suffix) or kilobytes
+ ("kb" suffix) or megabytes ("Mb" suffix).
+ string (optional): The string to repeat in the response. Defaults to "a".
+
+ Example:
+ /resources/large.py?size=32Mb&string=ab
+ """
+ if not "size" in request.GET:
+ 400, "Need an integer bytes parameter"
+
+ bytes_value = request.GET.first("size")
+
+ chunk_size = 1024
+
+ multipliers = {"kb": 1024,
+ "Mb": 1024*1024}
+
+ suffix = bytes_value[-2:]
+ if suffix in multipliers:
+ multiplier = multipliers[suffix]
+ bytes_value = bytes_value[:-2] * multiplier
+
+ try:
+ num_bytes = int(bytes_value)
+ except ValueError:
+ return 400, "Bytes must be an integer possibly with a kb or Mb suffix"
+
+ string = str(request.GET.first("string", "a"))
+
+ chunk = string * chunk_size
+
+ def content():
+ bytes_sent = 0
+ while bytes_sent < num_bytes:
+ if num_bytes - bytes_sent < len(chunk):
+ yield chunk[num_bytes - bytes_sent]
+ else:
+ yield chunk
+ bytes_sent += len(chunk)
+ return [("Content-Type", "text/plain")], content()