darkhttpd/devel/test_forward.py

27 lines
928 B
Python
Raw Permalink Normal View History

2021-01-17 09:29:23 +03:00
#!/usr/bin/env python3
2016-01-23 12:05:02 +03:00
# This is run by the "run-tests" script.
2013-04-28 18:31:54 +04:00
import unittest
from test import TestHelper, Conn, parse
class TestForward(TestHelper):
def test_forward_root(self):
2021-01-17 09:29:23 +03:00
resp = self.get('/', req_hdrs={'Host': 'example.com'})
2013-04-28 18:31:54 +04:00
status, hdrs, body = parse(resp)
self.assertContains(status, "301 Moved Permanently")
expect = "http://www.example.com/"
2021-01-17 09:29:23 +03:00
self.assertEqual(hdrs["Location"], expect)
2013-04-28 18:31:54 +04:00
self.assertContains(body, expect)
def test_forward_relative(self):
2021-01-17 09:29:23 +03:00
resp = self.get('/foo/bar', req_hdrs={'Host': 'secure.example.com'})
2013-04-28 18:31:54 +04:00
status, hdrs, body = parse(resp)
self.assertContains(status, "301 Moved Permanently")
expect = "https://www.example.com/secure/foo/bar"
2021-01-17 09:29:23 +03:00
self.assertEqual(hdrs["Location"], expect)
2013-04-28 18:31:54 +04:00
self.assertContains(body, expect)
if __name__ == '__main__':
unittest.main()
# vim:set ts=4 sw=4 et: