Refactoring RequestInit to use a Builder Pattern#22521
Refactoring RequestInit to use a Builder Pattern#22521bors-servo merged 1 commit intoservo:masterfrom
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon. |
|
Heads up! This PR modifies the following files:
|
|
|
579725c to
7a5ef1b
Compare
jdm
left a comment
There was a problem hiding this comment.
Sorry about the delay! Thanks for making these changes; they have made clear some interesting holes in our current network requests that I plan to file issues about!
components/script/fetch.rs
Outdated
| cache_mode: request.cache_mode, | ||
| ..NetTraitsRequestInit::default() | ||
| } | ||
| NetTraitsRequestInit::new(request.url()) |
There was a problem hiding this comment.
I would actually like to revert the change to this function, and remove the use of ..NetTraitsRequesInit::default(). That will make the compiler catch when we add members to NetTraitsRequestInit and need to be sure they are initialized correctly.
There was a problem hiding this comment.
I would like to revert this particular change: this method should construct a new NetTraitsRequestInit object with an explicit structvliteral that initializes every field (instead of using ..NetTraitsRequestInit::default()).
There was a problem hiding this comment.
What do you think about a method overload to the method to the Builder new passing all the arguments or the Request Object?
I'm just thinking about the separation of concerns.
There was a problem hiding this comment.
Then we will be able to construct this object without setting the properties directly by removing the "pub" from them.
e.g.:
RequestBuilder {
url: url
...
}
It will throw an error if you are building outside of his scope.
There was a problem hiding this comment.
The advantage of allowing some code like request_init_from_request to create the RequestInit value directly is that it's easier to understand code like use_url_credentials: false instead of a false value that is one of 20 arguments. I think it's fine to keep the field values of RequestInit public and build it directly, rather than adding a method.
|
|
My apologies, I was away. I gonna retake this task and finish it. |
|
☔ The latest upstream changes (presumably #23103) made this pull request unmergeable. Please resolve the merge conflicts. |
7a5ef1b to
1bb9073
Compare
f3b6ef9 to
2712351
Compare
|
@lucasfantacuci: 🔑 Insufficient privileges: not in try users |
1 similar comment
|
@lucasfantacuci: 🔑 Insufficient privileges: not in try users |
…nit, r=jdm Refactoring RequestInit to use a Builder Pattern <!-- Please describe your changes on the following line: --> If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22427 - [x] These changes do not require tests because it is a code refactoring. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22521) <!-- Reviewable:end -->
|
@bors-servo retry |
…nit, r=jdm Refactoring RequestInit to use a Builder Pattern <!-- Please describe your changes on the following line: --> If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22427 - [x] These changes do not require tests because it is a code refactoring. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22521) <!-- Reviewable:end -->
components/script/fetch.rs
Outdated
| use ipc_channel::router::ROUTER; | ||
| use js::jsapi::JSAutoCompartment; | ||
| use net_traits::request::RequestInit as NetTraitsRequestInit; | ||
| use net_traits::request::RequestBuilder as NetTraitsRequestInit; |
There was a problem hiding this comment.
This probably doesn't need the renaming anymore.
components/script/fetch.rs
Outdated
| use_cors_preflight: request.use_cors_preflight, | ||
| credentials_mode: request.credentials_mode, | ||
| use_url_credentials: request.use_url_credentials, | ||
| use_url_credentials: false, |
There was a problem hiding this comment.
Why is this changed to false?
There was a problem hiding this comment.
It may be a lack of attention.
There was a problem hiding this comment.
The default value is false.
c3803b0 to
6b2be9b
Compare
|
@bors-servo r=jdm,KiChjang Thanks! |
|
📌 Commit 6b2be9b has been approved by |
…nit, r=jdm,KiChjang Refactoring RequestInit to use a Builder Pattern <!-- Please describe your changes on the following line: --> If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22427 - [x] These changes do not require tests because it is a code refactoring. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22521) <!-- Reviewable:end -->
|
💥 Test timed out |
|
@bors-servo retry |
…nit, r=jdm,KiChjang Refactoring RequestInit to use a Builder Pattern <!-- Please describe your changes on the following line: --> If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22427 - [x] These changes do not require tests because it is a code refactoring. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22521) <!-- Reviewable:end -->
|
@bors-servo retry |
…nit, r=jdm,KiChjang Refactoring RequestInit to use a Builder Pattern <!-- Please describe your changes on the following line: --> If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22427 - [x] These changes do not require tests because it is a code refactoring. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22521) <!-- Reviewable:end -->
|
☀️ Test successful - android-mac, arm32, arm64, linux-rel-css, linux-rel-wpt, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, magicleap, status-taskcluster |
If RequestInit::new accepts all of the mandatory arguments and then the builder pattern is used for customizable options, the resulting code might be easier to match against specification text like
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is