Skip to content

Refactoring RequestInit to use a Builder Pattern#22521

Merged
bors-servo merged 1 commit intoservo:masterfrom
lucasfantacuci:use_build_pattern_with_requestinit
Apr 11, 2019
Merged

Refactoring RequestInit to use a Builder Pattern#22521
bors-servo merged 1 commit intoservo:masterfrom
lucasfantacuci:use_build_pattern_with_requestinit

Conversation

@lucasfantacuci
Copy link
Copy Markdown

@lucasfantacuci lucasfantacuci commented Dec 21, 2018

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 -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix Use builder pattern with RequestInit #22427
  • These changes do not require tests because it is a code refactoring.

This change is Reviewable

@highfive
Copy link
Copy Markdown

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
Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/net_traits/request.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 21, 2018
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 21, 2018
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 21, 2018
@lucasfantacuci
Copy link
Copy Markdown
Author

lucasfantacuci commented Dec 21, 2018

I implemented the builder pattern as a non-consuming builder. ref: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html

@lucasfantacuci lucasfantacuci force-pushed the use_build_pattern_with_requestinit branch from 579725c to 7a5ef1b Compare December 21, 2018 19:39
@lucasfantacuci lucasfantacuci changed the title WIP: Use builder pattern with RequestInit Refactoring RequestInit to use a Builder Pattern Dec 21, 2018
Copy link
Copy Markdown
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()).

Copy link
Copy Markdown
Author

@lucasfantacuci lucasfantacuci Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think now?

Copy link
Copy Markdown
Author

@lucasfantacuci lucasfantacuci Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@jdm jdm Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i've got you.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 15, 2019
@jdm
Copy link
Copy Markdown
Member

jdm commented Jan 15, 2019

error: unused import: `std::default::Default`
  --> components/net_traits/request.rs:11:5
   |
11 | use std::default::Default;
   |     ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D unused-imports` implied by `-D warnings`

@lucasfantacuci
Copy link
Copy Markdown
Author

My apologies, I was away. I gonna retake this task and finish it.

@bors-servo
Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #23103) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Apr 3, 2019
@lucasfantacuci lucasfantacuci force-pushed the use_build_pattern_with_requestinit branch from 7a5ef1b to 1bb9073 Compare April 3, 2019 20:43
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Apr 3, 2019
@lucasfantacuci lucasfantacuci changed the title Refactoring RequestInit to use a Builder Pattern [WIP]Refactoring RequestInit to use a Builder Pattern Apr 4, 2019
@lucasfantacuci lucasfantacuci force-pushed the use_build_pattern_with_requestinit branch 5 times, most recently from f3b6ef9 to 2712351 Compare April 4, 2019 18:29
@bors-servo
Copy link
Copy Markdown
Contributor

@lucasfantacuci: 🔑 Insufficient privileges: not in try users

1 similar comment
@bors-servo
Copy link
Copy Markdown
Contributor

@lucasfantacuci: 🔑 Insufficient privileges: not in try users

bors-servo pushed a commit that referenced this pull request Apr 10, 2019
…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 -->
@jdm
Copy link
Copy Markdown
Member

jdm commented Apr 10, 2019

@bors-servo retry

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit c3803b0 with merge 5370151...

bors-servo pushed a commit that referenced this pull request Apr 10, 2019
…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 -->
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoCompartment;
use net_traits::request::RequestInit as NetTraitsRequestInit;
use net_traits::request::RequestBuilder as NetTraitsRequestInit;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably doesn't need the renaming anymore.

use_cors_preflight: request.use_cors_preflight,
credentials_mode: request.credentials_mode,
use_url_credentials: request.use_url_credentials,
use_url_credentials: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed to false?

Copy link
Copy Markdown
Author

@lucasfantacuci lucasfantacuci Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a lack of attention.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is false.

@lucasfantacuci lucasfantacuci force-pushed the use_build_pattern_with_requestinit branch from c3803b0 to 6b2be9b Compare April 10, 2019 17:02
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Apr 10, 2019
@KiChjang
Copy link
Copy Markdown
Contributor

@bors-servo r=jdm,KiChjang

Thanks!

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit 6b2be9b has been approved by jdm,KiChjang

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 10, 2019
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 6b2be9b with merge cb5dce5...

bors-servo pushed a commit that referenced this pull request Apr 10, 2019
…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
Copy link
Copy Markdown
Contributor

💥 Test timed out

@KiChjang
Copy link
Copy Markdown
Contributor

@bors-servo retry

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 6b2be9b with merge f14d199...

bors-servo pushed a commit that referenced this pull request Apr 11, 2019
…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 -->
@jdm
Copy link
Copy Markdown
Member

jdm commented Apr 11, 2019

@bors-servo retry

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 6b2be9b with merge 9ab0af0...

bors-servo pushed a commit that referenced this pull request Apr 11, 2019
…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
Copy link
Copy Markdown
Contributor

☀️ 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
Approved by: jdm,KiChjang
Pushing 9ab0af0 to master...

@bors-servo bors-servo merged commit 6b2be9b into servo:master Apr 11, 2019
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 11, 2019
@lucasfantacuci lucasfantacuci deleted the use_build_pattern_with_requestinit branch April 11, 2019 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use builder pattern with RequestInit

9 participants