forked from lighttpd/lighttpd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht-header-modify.py
76 lines (66 loc) · 2.09 KB
/
t-header-modify.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
from base import *
from requests import *
class TestHeaderAdd(CurlRequest):
# use capture from previous regex conditional
config = """
header.add "Test-Header" => "%{req.query}";
header.add "Test-Header" => "%{req.path}";
respond;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 2 or h[0] != "simple_query" or h[1] != "/path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderAppend(CurlRequest):
# use capture from previous regex conditional
config = """
header.append "Test-Header" => "%{req.query}";
header.append "Test-Header" => "%{req.path}";
respond;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 1 or h[0] != "simple_query, /path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderOverwrite(CurlRequest):
# use capture from previous regex conditional
config = """
header.overwrite "Test-Header" => "%{req.query}";
header.overwrite "Test-Header" => "%{req.path}";
respond;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 1 or h[0] != "/path":
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class TestHeaderRemove(CurlRequest):
# use capture from previous regex conditional
config = """
header.add "Test-Header" => "%{req.query}";
header.remove "Test-Header";
respond;
"""
URL = "/path?simple_query"
def CheckResponse(self):
h = map(lambda x: x[1], filter(lambda x: x[0] == "Test-Header", self.resp_header_list))
if len(h) != 0:
print >>Env.log, repr(h)
raise BaseException("Unexpected headers 'Test-Header'")
return True
class Test(GroupTest):
group = [
TestHeaderAdd,
TestHeaderAppend,
TestHeaderOverwrite,
TestHeaderRemove,
]