diff --git a/CODEOWNERS b/CODEOWNERS index f9288ca9..0877a44f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -9,4 +9,6 @@ # AZURE FUNCTIONS TEAM # For all file changes, github would automatically include the following people in the PRs. # -* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria \ No newline at end of file + +* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria + diff --git a/azure/functions/_http_asgi.py b/azure/functions/_http_asgi.py index 7be3101c..372dc0fd 100644 --- a/azure/functions/_http_asgi.py +++ b/azure/functions/_http_asgi.py @@ -5,6 +5,7 @@ import logging import asyncio from asyncio import Event, Queue +from urllib.parse import ParseResult, urlparse from warnings import warn from wsgiref.headers import Headers @@ -22,6 +23,8 @@ def __init__(self, func_req: HttpRequest, self.asgi_version = ASGI_VERSION self.asgi_spec_version = ASGI_SPEC_VERSION self._headers = func_req.headers + url: ParseResult = urlparse(func_req.url) + self.asgi_url_scheme = url.scheme super().__init__(func_req, func_ctx) def _get_encoded_http_headers(self) -> List[Tuple[bytes, bytes]]: @@ -49,7 +52,7 @@ def to_asgi_http_scope(self): "asgi.spec_version": self.asgi_spec_version, "http_version": "1.1", "method": self.request_method, - "scheme": "https", + "scheme": self.asgi_url_scheme, "path": self.path_info, "raw_path": _raw_path, "query_string": _query_string, diff --git a/tests/test_http_asgi.py b/tests/test_http_asgi.py index 7125cd80..465f7600 100644 --- a/tests/test_http_asgi.py +++ b/tests/test_http_asgi.py @@ -198,7 +198,19 @@ def test_middleware_calls_app(self): test_body = b'Hello world!' app.response_body = test_body app.response_code = 200 - req = func.HttpRequest(method='get', url='/test', body=b'') + req = self._generate_func_request() + response = AsgiMiddleware(app).handle(req) + + # Verify asserted + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get_body(), test_body) + + def test_middleware_calls_app_http(self): + app = MockAsgiApplication() + test_body = b'Hello world!' + app.response_body = test_body + app.response_code = 200 + req = self._generate_func_request(url="http://a.b.com") response = AsgiMiddleware(app).handle(req) # Verify asserted