Skip to content

Commit c7c31dd

Browse files
Allow http scheme for AsgiRequest (#198)
* parse url scheme to allow http or https * added & fixed test * codeowner --------- Co-authored-by: wangbill <[email protected]>
1 parent f79ff41 commit c7c31dd

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CODEOWNERS

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
# AZURE FUNCTIONS TEAM
1010
# For all file changes, github would automatically include the following people in the PRs.
1111
#
12-
* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria
12+
13+
* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria
14+

azure/functions/_http_asgi.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import asyncio
77
from asyncio import Event, Queue
8+
from urllib.parse import ParseResult, urlparse
89
from warnings import warn
910
from wsgiref.headers import Headers
1011

@@ -22,6 +23,8 @@ def __init__(self, func_req: HttpRequest,
2223
self.asgi_version = ASGI_VERSION
2324
self.asgi_spec_version = ASGI_SPEC_VERSION
2425
self._headers = func_req.headers
26+
url: ParseResult = urlparse(func_req.url)
27+
self.asgi_url_scheme = url.scheme
2528
super().__init__(func_req, func_ctx)
2629

2730
def _get_encoded_http_headers(self) -> List[Tuple[bytes, bytes]]:
@@ -49,7 +52,7 @@ def to_asgi_http_scope(self):
4952
"asgi.spec_version": self.asgi_spec_version,
5053
"http_version": "1.1",
5154
"method": self.request_method,
52-
"scheme": "https",
55+
"scheme": self.asgi_url_scheme,
5356
"path": self.path_info,
5457
"raw_path": _raw_path,
5558
"query_string": _query_string,

tests/test_http_asgi.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,19 @@ def test_middleware_calls_app(self):
198198
test_body = b'Hello world!'
199199
app.response_body = test_body
200200
app.response_code = 200
201-
req = func.HttpRequest(method='get', url='/test', body=b'')
201+
req = self._generate_func_request()
202+
response = AsgiMiddleware(app).handle(req)
203+
204+
# Verify asserted
205+
self.assertEqual(response.status_code, 200)
206+
self.assertEqual(response.get_body(), test_body)
207+
208+
def test_middleware_calls_app_http(self):
209+
app = MockAsgiApplication()
210+
test_body = b'Hello world!'
211+
app.response_body = test_body
212+
app.response_code = 200
213+
req = self._generate_func_request(url="http://a.b.com")
202214
response = AsgiMiddleware(app).handle(req)
203215

204216
# Verify asserted

0 commit comments

Comments
 (0)