forked from cherokee/webserver
/
089-gzip-encoding.py
40 lines (29 loc) · 1.03 KB
/
089-gzip-encoding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from base import *
from util import *
from cStringIO import StringIO
from gzip import GzipFile
MAGIC = "Random text follows: " + str_random (10 * 1024)
CONF = """
vserver!1!rule!890!match = directory
vserver!1!rule!890!match!directory = /gzip1
vserver!1!rule!890!handler = file
vserver!1!rule!890!encoder!gzip = 1
"""
class Test (TestBase):
def __init__ (self):
TestBase.__init__ (self, __file__)
self.name = "GZip encoding 10k"
self.request = "GET /gzip1/file.txt HTTP/1.0\r\n" +\
"Accept-Encoding: gzip\r\n"
self.conf = CONF
self.expected_error = 200
self.forbidden_content = "Random text follows"
def CustomTest (self):
body_gz = self.reply[self.reply.find("\r\n\r\n")+4:]
body = GzipFile('','r',0,StringIO(body_gz)).read()
if body != MAGIC:
return -1
return 0
def Prepare (self, www):
self.Mkdir (www, "gzip1")
self.WriteFile (www, "gzip1/file.txt", 0444, MAGIC)