-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
allow user to pass middleware options #442
Conversation
…add_middleware call
@geospatial-jeff is this PR still a good change? If so, since it's breaking, we should decide if we want it to go in before or after #450. |
After looking at this again, IMO this is a non-breaking change to the type signature of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work here!
Let's hold of til #625 get's merged but this PR is ✅ |
Greetings @vincentsarago @geospatial-jeff @jonhealy1, How do I convert this type of middleware definition with these new changes? @app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response |
@pedro-cf using |
Related Issue(s):
Description:
The goal of this PR is to make it easier for users to configure middleware passed to the application. Starlette / fastapi expect the middleware class and arguments to that class to be passed separately, the
starlette.middleware.Middleware
class encapsulates this.StacApi.middleware
instance variable (List[type]
->List[Middleware]
)StacApi.add_middleware
for adding middleware to the underlying fastapi application. This method uses the same business logic asStarlette.add_middleware
.Before
After
PR Checklist:
pre-commit run --all-files
)make test
)make docs
)