Skip to content

Commit

Permalink
fix(api-gateway): HTTP API strip stage name from request path (#622)
Browse files Browse the repository at this point in the history
* fix(api-gateway): strip stage name from request path

* fix: indent
NOTE: Don't use github ui for merge conflicts
  • Loading branch information
Michael Brewer authored Aug 19, 2021
1 parent 4745070 commit b2773d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def stage_variables(self) -> Optional[Dict[str, str]]:

@property
def path(self) -> str:
stage = self.request_context.stage
if stage != "$default":
return self.raw_path[len("/" + stage) :]
return self.raw_path

@property
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/event_handler/test_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,22 @@ def foo():
# THEN a route for `/foo/status` should be found
# so no prefix was stripped from the request path
assert response["statusCode"] == 200


def test_api_gateway_v2_raw_path():
# GIVEN a Http API V2 proxy type event
# AND a custom stage name "dev" and raw path "/dev/foo"
app = ApiGatewayResolver(proxy_type=ProxyEventType.APIGatewayProxyEventV2)
event = {"rawPath": "/dev/foo", "requestContext": {"http": {"method": "GET"}, "stage": "dev"}}

@app.get("/foo")
def foo():
return {}

# WHEN calling the event handler
# WITH a route "/foo"
result = app(event, {})

# THEN process event correctly
assert result["statusCode"] == 200
assert result["headers"]["Content-Type"] == content_types.APPLICATION_JSON

0 comments on commit b2773d5

Please sign in to comment.