@@ -1857,12 +1857,17 @@ def wrapped_event(request: Request) -> Response:
1857
1857
return response .to_dict (self .api .binary_types )
1858
1858
1859
1859
def _main_rest_api_handler (self , event : Any , context : Any ) -> Response :
1860
- resource_path = event .get ('requestContext' , {}).get ('resourcePath' )
1861
- if resource_path is None :
1862
- return error_response (error_code = 'InternalServerError' ,
1863
- message = 'Unknown request.' ,
1864
- http_status_code = 500 )
1865
- http_method = event ['requestContext' ]['httpMethod' ]
1860
+ current_request : Optional [Request ] = self .current_request
1861
+ if current_request :
1862
+ resource_path = current_request .path
1863
+ http_method = current_request .method
1864
+ else :
1865
+ resource_path = event .get ('requestContext' , {}).get ('resourcePath' )
1866
+ if resource_path is None :
1867
+ return error_response (error_code = 'InternalServerError' ,
1868
+ message = 'Unknown request.' ,
1869
+ http_status_code = 500 )
1870
+ http_method = event ['requestContext' ]['httpMethod' ]
1866
1871
if http_method not in self .routes [resource_path ]:
1867
1872
allowed_methods = ', ' .join (self .routes [resource_path ].keys ())
1868
1873
return error_response (
@@ -1872,8 +1877,12 @@ def _main_rest_api_handler(self, event: Any, context: Any) -> Response:
1872
1877
headers = {'Allow' : allowed_methods })
1873
1878
route_entry = self .routes [resource_path ][http_method ]
1874
1879
view_function = route_entry .view_function
1875
- function_args = {name : event ['pathParameters' ][name ]
1876
- for name in route_entry .view_args }
1880
+ if current_request :
1881
+ function_args = {name : current_request .uri_params [name ]
1882
+ for name in route_entry .view_args }
1883
+ else :
1884
+ function_args = {name : event ['pathParameters' ][name ]
1885
+ for name in route_entry .view_args }
1877
1886
self .lambda_context = context
1878
1887
# We're getting the CORS headers before validation to be able to
1879
1888
# output desired headers with
@@ -1883,8 +1892,8 @@ def _main_rest_api_handler(self, event: Any, context: Any) -> Response:
1883
1892
# We're doing the header validation after creating the request
1884
1893
# so can leverage the case insensitive dict that the Request class
1885
1894
# uses for headers.
1886
- if self . current_request and route_entry .content_types :
1887
- content_type = self . current_request .headers .get (
1895
+ if current_request and route_entry .content_types :
1896
+ content_type = current_request .headers .get (
1888
1897
'content-type' , 'application/json' )
1889
1898
if not _matches_content_type (content_type ,
1890
1899
route_entry .content_types ):
@@ -1900,8 +1909,8 @@ def _main_rest_api_handler(self, event: Any, context: Any) -> Response:
1900
1909
self ._add_cors_headers (response , cors_headers )
1901
1910
1902
1911
response_headers = CaseInsensitiveMapping (response .headers )
1903
- if self . current_request and not self ._validate_binary_response (
1904
- self . current_request .headers , response_headers ):
1912
+ if current_request and not self ._validate_binary_response (
1913
+ current_request .headers , response_headers ):
1905
1914
content_type = response_headers .get ('content-type' , '' )
1906
1915
return error_response (
1907
1916
error_code = 'BadRequest' ,
0 commit comments