-
-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat before request #1125
base: main
Are you sure you want to change the base?
Feat before request #1125
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
for more information, see https://pre-commit.ci
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.
Hey @tengfeisky 👋
Thanks for the PR :D I have some comments. Could you have a look?
|
||
@app.get("/sync/global/middlewares/with_request") | ||
def sync_global_middlewares_with_request(request: Request): | ||
print(request.headers) |
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.
why do we need this?
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.
Used for testing
|
||
@app.get("/async/global/middlewares/with_request") | ||
def sync_global_middlewares_with_request(request: Request): | ||
print(request.headers) |
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.
same question here.
if let Ok(tuple) = function_args.downcast::<PyTuple>(py) { | ||
handler.call(tuple, Some(kwargs)) | ||
} else { | ||
handler.call((function_args,), Some(kwargs)) | ||
} |
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.
can you please explain this line of code to me?
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.
In Rust, this syntax (function_args,) creates a nested tuple in Python, similar to ((arg1,arg2),).
@@ -1,5 +1,6 @@ | |||
use crate::executors::{ | |||
execute_http_function, execute_middleware_function, execute_startup_handler, | |||
execute_http_function, execute_middleware_after_request, execute_middleware_function, |
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.
I think we can do slightly better here.
i.e. execute_middleware_after_request
and execute_middleware_function
are not correct nomenclature imo.
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.
What is your suggestion then?
Description
This PR adds request parameter to after_request middleware
Summary
This PR adds the request parameter to the after_request middleware function to enable proper propagation of trace_id between request and response headers. This change supports distributed tracing functionality by ensuring that the trace_id remains consistent throughout the request lifecycle and can be properly passed to downstream services.
PR Checklist
Please ensure that:
Pre-Commit Instructions: