diff --git a/src/hio/core/http/serving.py b/src/hio/core/http/serving.py index 647156f..f394e6e 100644 --- a/src/hio/core/http/serving.py +++ b/src/hio/core/http/serving.py @@ -12,7 +12,7 @@ import datetime import mimetypes -from urllib.parse import urlsplit, unquote +from urllib.parse import urlsplit, unquote, quote from contextlib import contextmanager from ... import help @@ -725,7 +725,7 @@ def buildEnviron(self, requestant): environ['SERVER_PORT'] = str(self.servant.eha[1]) # 8888 environ['SERVER_PROTOCOL'] = "HTTP/{0}.{1}".format(*requestant.version) # used by request http/1.1 environ['SCRIPT_NAME'] = u'' - environ['PATH_INFO'] = requestant.path # /hello?name=john + environ['PATH_INFO'] = quote(requestant.path) # /hello?name=john # Optional CGI variables environ['QUERY_STRING'] = requestant.query # name=john diff --git a/tests/core/http/falcon/test_falcon.py b/tests/core/http/falcon/test_falcon.py index d8ce0b3..0d21da8 100644 --- a/tests/core/http/falcon/test_falcon.py +++ b/tests/core/http/falcon/test_falcon.py @@ -316,6 +316,44 @@ def on_get(self, req, rep): exampleBackend = ExampleBackendEnd(tymth=tymist.tymen()) exapp.add_route('/example/backend', exampleBackend) +def test_get_request_with_utf8(): + """ + Test a request with a utf-8 character + """ + tymist.tyme = 0.0 # reset for each test + with http.openServer(port=8101, bufsize=131072, app=exapp, \ + tymth=tymist.tymen()) as server: + + assert server.servant.ha == ('0.0.0.0', 8101) + assert server.servant.eha == ('127.0.0.1', 8101) + + # request containing utf-8 character + path = "http://{}:{}{}".format('localhost', + server.servant.eha[1], + "/�") + headers = help.Hict([('Accept', 'application/json'), + ('Content-Length', 0)]) + + with http.openClient(bufsize=131072, method='GET', path=path, \ + headers=headers, reconnectable=True, \ + tymth=tymist.tymen()) as client: + + client.transmit() + while (client.requests or client.connector.txbs or not client.responses or + not server.idle()): + server.service() + time.sleep(0.05) + client.service() + time.sleep(0.05) + tymist.tick(tock=0.1) + + assert len(client.responses) == 1 + rep = client.responses.popleft() + + # utf-8 character is not supported in the path + assert rep['status'] == 404 + + """Done Test """ def test_get_backend():