2626 LambdaAtEdge ,
2727]
2828
29+ DEFAULT_TEXT_MIME_TYPES : List [str ] = [
30+ "text/" ,
31+ "application/json" ,
32+ "application/javascript" ,
33+ "application/xml" ,
34+ "application/vnd.api+json" ,
35+ "application/vnd.oai.openapi" ,
36+ ]
37+
2938
3039class Mangum :
3140 def __init__ (
@@ -34,6 +43,7 @@ def __init__(
3443 lifespan : LifespanMode = "auto" ,
3544 api_gateway_base_path : str = "/" ,
3645 custom_handlers : Optional [List [Type [LambdaHandler ]]] = None ,
46+ text_mime_types : Optional [List [str ]] = None ,
3747 ) -> None :
3848 if lifespan not in ("auto" , "on" , "off" ):
3949 raise ConfigurationError (
@@ -42,24 +52,22 @@ def __init__(
4252
4353 self .app = app
4454 self .lifespan = lifespan
45- self .api_gateway_base_path = api_gateway_base_path or "/"
46- self .config = LambdaConfig (api_gateway_base_path = self .api_gateway_base_path )
4755 self .custom_handlers = custom_handlers or []
56+ self .config = LambdaConfig (
57+ api_gateway_base_path = api_gateway_base_path or "/" ,
58+ text_mime_types = text_mime_types or [* DEFAULT_TEXT_MIME_TYPES ],
59+ )
4860
4961 def infer (self , event : LambdaEvent , context : LambdaContext ) -> LambdaHandler :
5062 for handler_cls in chain (self .custom_handlers , HANDLERS ):
5163 if handler_cls .infer (event , context , self .config ):
52- handler = handler_cls (event , context , self .config )
53- break
54- else :
55- raise RuntimeError ( # pragma: no cover
56- "The adapter was unable to infer a handler to use for the event. This "
57- "is likely related to how the Lambda function was invoked. (Are you "
58- "testing locally? Make sure the request payload is valid for a "
59- "supported handler.)"
60- )
61-
62- return handler
64+ return handler_cls (event , context , self .config )
65+ raise RuntimeError ( # pragma: no cover
66+ "The adapter was unable to infer a handler to use for the event. This "
67+ "is likely related to how the Lambda function was invoked. (Are you "
68+ "testing locally? Make sure the request payload is valid for a "
69+ "supported handler.)"
70+ )
6371
6472 def __call__ (self , event : LambdaEvent , context : LambdaContext ) -> dict :
6573 handler = self .infer (event , context )
0 commit comments