summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_wsgiref.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_wsgiref.py')
-rw-r--r--Lib/test/test_wsgiref.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index e213d77..4076b68 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -1,11 +1,10 @@
-from __future__ import nested_scopes # Backward compat for 2.1
from unittest import TestCase
from wsgiref.util import setup_testing_defaults
from wsgiref.headers import Headers
from wsgiref.handlers import BaseHandler, BaseCGIHandler
from wsgiref import util
from wsgiref.validate import validator
-from wsgiref.simple_server import WSGIServer, WSGIRequestHandler, demo_app
+from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
from wsgiref.simple_server import make_server
from io import StringIO, BytesIO, BufferedReader
from socketserver import BaseServer
@@ -14,9 +13,11 @@ from platform import python_implementation
import os
import re
import sys
+import unittest
from test import support
+
class MockServer(WSGIServer):
"""Non-socket HTTP server"""
@@ -48,6 +49,18 @@ def hello_app(environ,start_response):
])
return [b"Hello, world!"]
+
+def header_app(environ, start_response):
+ start_response("200 OK", [
+ ('Content-Type', 'text/plain'),
+ ('Date', 'Mon, 05 Jun 2006 18:49:54 GMT')
+ ])
+ return [';'.join([
+ environ['HTTP_X_TEST_HEADER'], environ['QUERY_STRING'],
+ environ['PATH_INFO']
+ ]).encode('iso-8859-1')]
+
+
def run_amock(app=hello_app, data=b"GET / HTTP/1.0\n\n"):
server = make_server("", 80, app, MockServer, MockHandler)
inp = BufferedReader(BytesIO(data))
@@ -118,6 +131,19 @@ class IntegrationTests(TestCase):
out, err = run_amock()
self.check_hello(out)
+ def test_environ(self):
+ request = (
+ b"GET /p%61th/?query=test HTTP/1.0\n"
+ b"X-Test-Header: Python test \n"
+ b"X-Test-Header: Python test 2\n"
+ b"Content-Length: 0\n\n"
+ )
+ out, err = run_amock(header_app, request)
+ self.assertEqual(
+ out.splitlines()[-1],
+ b"Python test,Python test 2;query=test;/path/"
+ )
+
def test_request_length(self):
out, err = run_amock(data=b"GET " + (b"x" * 65537) + b" HTTP/1.0\n\n")
self.assertEqual(out.splitlines()[0],