@@ -61,31 +61,31 @@ def resolve(self, event: Dict, context: LambdaContext) -> Dict:
61
61
62
62
route , args = self ._find_route (self .current_event .http_method , self .current_event .path )
63
63
result = route .func (** args )
64
+ status_code : int = result [0 ]
65
+ content_type : str = result [1 ]
66
+ body : Union [str , bytes ] = result [2 ]
67
+ headers = {"Content-Type" : content_type }
64
68
65
- status : int = result [0 ]
66
- response : Dict [str , Any ] = {"statusCode" : status }
67
-
68
- headers = {"Content-Type" : result [1 ]}
69
69
if route .cors :
70
70
headers ["Access-Control-Allow-Origin" ] = "*"
71
71
headers ["Access-Control-Allow-Methods" ] = route .method
72
72
headers ["Access-Control-Allow-Credentials" ] = "true"
73
+
73
74
if route .cache_control :
74
- headers ["Cache-Control" ] = route .cache_control if status == 200 else "no-cache"
75
- response ["headers" ] = headers
75
+ headers ["Cache-Control" ] = route .cache_control if status_code == 200 else "no-cache"
76
76
77
- body : Union [str , bytes ] = result [2 ]
78
77
if route .compress and "gzip" in (self .current_event .get_header_value ("accept-encoding" ) or "" ):
79
- gzip_compress = zlib .compressobj (9 , zlib .DEFLATED , zlib .MAX_WBITS | 16 )
80
78
if isinstance (body , str ):
81
79
body = bytes (body , "utf-8" )
80
+ gzip_compress = zlib .compressobj (9 , zlib .DEFLATED , zlib .MAX_WBITS | 16 )
82
81
body = gzip_compress .compress (body ) + gzip_compress .flush ()
82
+
83
+ base64_encoded = False
83
84
if isinstance (body , bytes ):
84
- response [ "isBase64Encoded" ] = True
85
+ base64_encoded = True
85
86
body = base64 .b64encode (body ).decode ()
86
- response ["body" ] = body
87
87
88
- return response
88
+ return { "statusCode" : status_code , "headers" : headers , "body" : body , "isBase64Encoded" : base64_encoded }
89
89
90
90
def _append (self , func : Callable , rule : str , method : str , cors : bool , compress : bool , cache_control : Optional [str ]):
91
91
self ._routes .append (RouteEntry (method , self ._build_rule_pattern (rule ), func , cors , compress , cache_control ))
0 commit comments