-
Notifications
You must be signed in to change notification settings - Fork 81
refactor: use foreign-type for request #211
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
Conversation
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.
Pull Request Overview
This PR refactors the Request struct to use the foreign_types::ForeignTypeRef trait instead of direct wrapper implementation. This change allows the Request object to avoid unnecessary copying of original ngx_http_request_t data by using a reference-based approach.
Key changes:
- Replace direct struct wrapping with
ForeignTypeReftrait implementation - Update all macro call sites to use
ForeignTypeRef::from_ptr_mut()instead of custom conversion - Add
foreign-typesdependency to enable the new pattern
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/http/request.rs | Refactored Request struct to implement ForeignTypeRef trait and updated all field access to use helper methods |
| src/http/upstream.rs | Updated macro to use ForeignTypeRef::from_ptr_mut() for request conversion |
| src/core/mod.rs | Added re-export of ForeignTypeRef trait |
| examples/upstream.rs | Updated example to use new ForeignTypeRef pattern and added import |
| examples/async.rs | Updated async example to use ForeignTypeRef conversion methods |
| Cargo.toml | Added foreign-types dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
pchickey
left a comment
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 agree that Request(ngx_http_request_t) was the wrong representation. I was going to propose that we make it Request(NonNull<ngx_http_request_t>) with a constructor fn from_http_request(NonNull<ngx_http_request_t>) -> Self and not use any &mut self methods, because nginx does not consider any *mut ngx_http_request_t to be unique, and the uniqueness property of Request does not make its use any more or less unsafe.
f023297 to
82b683d
Compare
xeioex
left a comment
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.
LGTM.
82b683d to
bdce0b4
Compare
bdce0b4 to
637361a
Compare
637361a to
3c46ae3
Compare
|
Closed because there are no meaningful changes in this PR. |
|
@ensh63 would you like me to work on a PR based on this rough sketch? #211 (review) |
|
I don't believe It's not a new problem, and I've been looking at the various approaches. |
Proposed changes
foreign_type::ForeignTypeReftrait is used to defineRequestobject. While generally the use of this object almost unchanged, reference trait allows to avoid unnecessary copying of originalngx_http_request_tdata.Checklist
Before creating a PR, run through this checklist and mark each as complete.