-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
http-quirks.py
49 lines (43 loc) · 1.54 KB
/
http-quirks.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
#!/usr/bin/env python
# Http quirks
# ===========
#
# During the work on SockJS few interesting aspects of Http were
# identified. Following tests try to trigger that. If the tests end
# with success - you can be more confident that your web server will
# survive clients that are violating some aspects of http.
#
# This tests aren't really a part of SockJS test suite, it's more
# about verification http quirks.
import unittest2 as unittest
import uuid
import urlparse
import httplib_fork as httplib
import os
test_top_url = os.environ.get('SOCKJS_URL', 'http://localhost:8081')
base_url = test_top_url + '/echo'
def POST_empty(url):
u = urlparse.urlparse(url)
if u.scheme == 'http':
conn = httplib.HTTPConnection(u.netloc)
elif u.scheme == 'https':
conn = httplib.HTTPSConnection(u.netloc)
else:
assert False, "Unsupported scheme " + u.scheme
path = u.path + ('?' + u.query if u.query else '')
conn.request('POST', path)
res = conn.getresponse()
headers = dict( (k.lower(), v) for k, v in res.getheaders() )
body = res.read()
conn.close()
return res.status, body, headers
class HttpQuirks(unittest.TestCase):
def test_emptyContentLengthForPost(self):
# Doing POST without Content-Length shouldn't break the
# server (it does break misultin)
trans_url = base_url + '/000/' + str(uuid.uuid4())
status, body, _ = POST_empty(trans_url + '/xhr')
self.assertEqual(body, 'o\n')
self.assertEqual(status, 200)
if __name__ == '__main__':
unittest.main()