Skip to content

Refactor HSTSList to use HashMap - #14794

Merged
bors-servo merged 1 commit into
servo:masterfrom
nmvk:hsts-refactor
Dec 30, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
nmvk:hsts-refactor

Conversation

@nmvk

@nmvk nmvk commented Dec 30, 2016 •

Copy link
Copy Markdown
Contributor

Refactored HSTSList to use HashMap, where the key of HashMap is the base domain. Every time when we check if a host is secure, we find the base domain of the host and get a vector of HSTS entries associated with the base domain.

While this will not give O(1) look up time, we would have a smaller list to iterate for every lookup. I have added one unit test to validate HashMap changes.


  • There are tests for these changes OR

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 30, 2016
Comment thread components/net/hsts.rs Outdated
e.matches_domain(host)
let base_domain = reg_host(host);

match self.entries_map.get(&base_domain) {

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.

nit: You can use:

self.entries_map.get(&base_domain).map_or(false, |entries| {
   // ...
})

To save a bit of indentation. Also applies below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@emilio emilio left a comment

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.

Looks good to me once those comments are addressed, thanks for doing this! :)

Comment thread components/net/hsts.rs Outdated
.ok()
.and_then(|c| decode(c).ok())
.and_then(|c| decode(c).ok());
if hsts_entries.is_some() {

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.

nit: Use:

hsts_entries.map(|entries| {
    //
})

Instead.

Comment thread components/net/hsts.rs Outdated
}
}

fn reg_host<'a>(url: &'a str) -> String {

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 don't think this is needed? Just use reg_suffix, and when needed do to_owned or similar, but you don't need a String all the time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I had to add let host = entry.host.clone(); to solve borrowing issue is this fine?

Refactored HSTSList to use HashMap, where the key of HashMap is the base
domain. Every time when we check if a host is secure, we find the base
domain of the host and get a vector of HSTS entries associated with the
base domain.

While this will not give O(1) look up time, we would have a smaller list
to iterate for every lookup. I have added one unit test to validate
HashMap changes.
@emilio

emilio commented Dec 30, 2016

Copy link
Copy Markdown
Member

@bors-servo r+

Yeah, it's ok.

Thanks for doing this! :)

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 6a14349 has been approved by emilio

@highfive highfive assigned emilio and unassigned nox Dec 30, 2016
@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 Dec 30, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6a14349 with merge b06f4ae...

bors-servo pushed a commit that referenced this pull request Dec 30, 2016
Refactor HSTSList to use HashMap

Refactored HSTSList to use HashMap, where the key of HashMap is the base domain. Every time when we check if a host is secure, we find the base domain of the host and get a vector of HSTS entries associated with the base domain.

While this will not give O(1) look up time, we would have a smaller list to iterate for every lookup. I have added one unit test to validate `HashMap` changes.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14756

<!-- Either: -->
- [X] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/14794)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit 6a14349 into servo:master Dec 30, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 30, 2016
@nmvk

nmvk commented Dec 31, 2016

Copy link
Copy Markdown
Contributor Author

Thanks @emilio

@nmvk
nmvk deleted the hsts-refactor branch December 31, 2016 04:04
@nmvk
nmvk restored the hsts-refactor branch December 31, 2016 04:04
@nmvk
nmvk deleted the hsts-refactor branch December 31, 2016 04:04
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 another backing store for the HSTS list.

5 participants