Remove the Redirect and Remapped wrapper variants from the Status enum.#2129
Remove the Redirect and Remapped wrapper variants from the Status enum.#2129thomas-zahner merged 5 commits intomasterfrom
Redirect and Remapped wrapper variants from the Status enum.#2129Conversation
…num. Previously, redirect and remap information was nested inside the Status enum, which forced every exhaustive match (~8 sites) to either recurse through these wrappers or delegate via an innermost() helper. This made the enum harder to work with and obscured the actual status. Key changes: - Status enum loses Redirected and Remapped variants (9 variants -> 9) - Remove innermost() and redirects() methods from Status - All is_success/is_error/etc. methods now match directly on self - ResponseBody gains redirects and remap fields - Response::new() accepts redirects and remap parameters - WebsiteChecker::check_website() returns (Status, Option<Redirects>) - RedirectHistory::handle_redirected() replaced with resolve() - Client::check() passes redirects/remap to Response, not Status - All exhaustive matches simplified (no more recursive delegation) - Redirect/remap details now rendered in ResponseBody::Display
dc437e5 to
f988413
Compare
katrinafyi
left a comment
There was a problem hiding this comment.
Very happy with the refactor and the resulting simplifications. Looks good!
It's not specific to this PR, but I was never clear on the separation between Response and ResponseBody.
In #2097, it was also my intention to store Remap inside Request and then store Request inside Response. With that, we would avoid needing to move all the fields across into Response(Body), like span, source, etc. Nothing needs to change in this PR, but just checking we're on the same page :)
Sounds like a plan. No objections right now. My only concern is that I've never been a huge fan of the standalone |
|
Yeah, the main use of ResponseBody is it appears in the response maps: pub(crate) success_map: HashMap<InputSource, HashSet<ResponseBody>>,where ResponseBody is basically a Response minus the InputSource. pub struct Response {
input_source: InputSource,
response_body: ResponseBody,
}This makes some sense, as the hashmap already has the input source in the key. But yeah, just something to keep in mind for later. |
thomas-zahner
left a comment
There was a problem hiding this comment.
Thank you @mre, I have no objections. I agree that we can clean up the Nones with a new PR as you explained.
Sorry for introducing this confusing approach in the first place. Additionally, the current nesting made it possible to introduce useless and confusing state such as containing Redirected or Remapped multiple times. This is something I didn't think about when I introduced it. So your refactor is definitely the way to go 👍
|
Cool! I will rebase the PR and apply the changes we agreed on when I get the chance. Will merge when everything is clean. |
As @katrinafyi pointed out this makes more sense since remaps are applied before redirects are followed.
|
Just some more lints to fix. 😅 @thomas-zahner, guess you're on it? |
|
Thanks for pushing this over the finishing line, Thomas! |
The goal of this refactor is to make a step towards cleaning up the
Statusenum as proposed in #2097.Previously, redirect and remap information was nested inside the
Statusenum, which forced every exhaustive match (~8 places) to either recurse through these wrappers or delegate via theinnermost()helper. This made the enum harder to work with and obscured the actual status.The proposal is to have redirect and remap data live as separate fields on
ResponseBody.This gets rid of innermost() and redirects() methods from Status and all is_success/is_error/etc. methods now match directly on self.
I am aware that the three
Nones in a row inResponseare pretty bad. The constructor already had too many positional params before this change, and I made it worse.However, this change will unlock the possibility to move redirects into
Outcomein the future, e.g.This way, we can get rid of the
Nonefields inResponseagain in the future when we introduceOutcome.(I attempted that first, but it turned out to be a much bigger refactor, so I broke out a smaller chunk for now.)