Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRefactoring RequestInit to use a Builder Pattern #22521
Conversation
highfive
commented
Dec 21, 2018
|
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. |
highfive
commented
Dec 21, 2018
|
Heads up! This PR modifies the following files:
|
|
|
579725c
to
7a5ef1b
|
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! |
| cache_mode: request.cache_mode, | ||
| ..NetTraitsRequestInit::default() | ||
| } | ||
| NetTraitsRequestInit::new(request.url()) |
This comment has been minimized.
This comment has been minimized.
jdm
Jan 15, 2019
Member
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jdm
Apr 4, 2019
Member
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()).
This comment has been minimized.
This comment has been minimized.
lucasfantacuci
Apr 4, 2019
•
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lucasfantacuci
Apr 5, 2019
•
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
jdm
Apr 8, 2019
•
Member
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.
This comment has been minimized.
This comment has been minimized.
|
|
My apologies, I was away. I gonna retake this task and finish it. |
|
|
7a5ef1b
to
1bb9073
f3b6ef9
to
2712351
|
@lucasfantacuci: |
1 similar comment
|
@lucasfantacuci: |
…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 -->
| @@ -24,7 +24,7 @@ use crate::task_source::TaskSourceName; | |||
| use ipc_channel::ipc; | |||
| use ipc_channel::router::ROUTER; | |||
| use js::jsapi::JSAutoCompartment; | |||
| use net_traits::request::RequestInit as NetTraitsRequestInit; | |||
| use net_traits::request::RequestBuilder as NetTraitsRequestInit; | |||
This comment has been minimized.
This comment has been minimized.
| use_cors_preflight: request.use_cors_preflight, | ||
| credentials_mode: request.credentials_mode, | ||
| use_url_credentials: request.use_url_credentials, | ||
| use_url_credentials: false, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c3803b0
to
6b2be9b
|
@bors-servo r=jdm,KiChjang Thanks! |
|
|
…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 -->
|
@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 -->
|
|
lucasfantacuci commentedDec 21, 2018
•
edited by CYBAI
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