Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow http scheme for AsgiRequest #198

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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

* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria

5 changes: 4 additions & 1 deletion azure/functions/_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]]:
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion tests/test_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading