From 1f7cc8e69ee1a7905c4c10aaf5720c71173684d8 Mon Sep 17 00:00:00 2001 From: david-perez <d@vidp.dev> Date: Fri, 20 Oct 2023 14:51:23 +0200 Subject: [PATCH] Update valid `Content-Type`s for example Python server (#2905) The service has a modeled event stream operation. It is exercised in the `event_stream_test`. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- examples/python/pokemon_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/python/pokemon_service.py b/examples/python/pokemon_service.py index 552d892ff..8eb1255f8 100644 --- a/examples/python/pokemon_service.py +++ b/examples/python/pokemon_service.py @@ -176,8 +176,8 @@ Next = Callable[[Request], Awaitable[Response]] @app.middleware async def check_content_type_header(request: Request, next: Next) -> Response: content_type = request.headers.get("content-type") - if content_type == "application/json": - logging.debug("found valid `application/json` content type") + if content_type in ["application/json", "application/vnd.amazon.eventstream"]: + logging.debug("found valid `%s` content type", content_type) else: logging.warning( "invalid content type %s, dumping headers: %s", @@ -203,7 +203,7 @@ async def add_x_amzn_answer_header(request: Request, next: Next) -> Response: async def check_x_amzn_answer_header(request: Request, next: Next) -> Response: # Check that `x-amzn-answer` is 42. if request.headers.get("x-amzn-answer") != "42": - # Return an HTTP 401 Unauthorized if the content type is not JSON. + # Return an HTTP 401 Unauthorized. raise MiddlewareException("Invalid answer", 401) return await next(request) -- GitLab