Skip to content

Commit

Permalink
Fix BrokenResourceError on starlette. See tiangolo/fastapi#4041 for m…
Browse files Browse the repository at this point in the history
…ore details.

Add middleware for handle requests without headers in request.
  • Loading branch information
eliorerz committed Jan 14, 2022
1 parent 4853c39 commit fff8b58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bug_master/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi import FastAPI, Request, Response
from fastapi.routing import APIRoute, APIRouter
from slack_sdk import signature
from starlette.responses import JSONResponse, StreamingResponse
from uvicorn_loguru_integration import run_uvicorn_loguru

from . import consts
Expand Down Expand Up @@ -56,6 +57,14 @@ async def custom_route_handler(request: Request) -> Response:
signature_verifier = signature.SignatureVerifier(consts.SIGNING_SECRET)


@app.middleware('http')
async def headers_middleware(request: Request, call_next: Callable):
if not hasattr(request, "headers"):
return JSONResponse(content={"message": "Invalid request"}, status_code=401)
response: StreamingResponse = await call_next(request)
return response


@router.post("/slack/config")
async def config(request: Request):
body = {k.decode(): v.pop().decode() for k, v in parse_qs(await request.body()).items()}
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
uvicorn==0.15.0
fastapi==0.70.0
fastapi==0.71.0
loguru==0.5.3
slackers==1.0.0
starlette==0.16.0
starlette==0.17.1
aiohttp==3.8.0
PyYAML==6.0
slack_sdk==3.11.2
Expand Down

0 comments on commit fff8b58

Please sign in to comment.