3
3
4
4
from typing import Dict , List , Tuple , Optional , Any , Union
5
5
import logging
6
+ from copy import copy
6
7
import asyncio
7
8
from asyncio import Event , Queue
8
9
from urllib .parse import ParseResult , urlparse
@@ -36,7 +37,7 @@ def _get_server_address(self):
36
37
return (self .server_name , int (self .server_port ))
37
38
return None
38
39
39
- def to_asgi_http_scope (self ):
40
+ def to_asgi_http_scope (self , state : Optional [ Dict ] = None ):
40
41
if self .path_info is not None :
41
42
_raw_path = self .path_info .encode ("utf-8" )
42
43
else :
@@ -60,6 +61,7 @@ def to_asgi_http_scope(self):
60
61
"headers" : self ._get_encoded_http_headers (),
61
62
"server" : self ._get_server_address (),
62
63
"client" : None ,
64
+ "state" : state ,
63
65
"azure_functions.function_directory" : self .af_function_directory ,
64
66
"azure_functions.function_name" : self .af_function_name ,
65
67
"azure_functions.invocation_id" : self .af_invocation_id ,
@@ -210,7 +212,8 @@ async def main(req, context):
210
212
211
213
async def _handle_async (self , req , context ):
212
214
asgi_request = AsgiRequest (req , context )
213
- scope = asgi_request .to_asgi_http_scope ()
215
+ # Shallow copy the state as-per the ASGI spec
216
+ scope = asgi_request .to_asgi_http_scope (state = copy (self .state ))
214
217
asgi_response = await AsgiResponse .from_app (self ._app ,
215
218
scope ,
216
219
req .get_body ())
0 commit comments