Skip to content

Proxito: adapt unresolver to make it usable for proxito #10037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 2, 2023

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 16, 2023

Instead of returning a partial response, I'm just raising an exception with the information from the context where it happened, this will be used in proxito to decide what to do (redirect, raise 404, etc)

@stsewd stsewd force-pushed the refactor-unresolver branch from 215718e to 4f10484 Compare February 16, 2023 01:39
@stsewd stsewd force-pushed the refactor-unresolver branch 2 times, most recently from fd683dd to 9186199 Compare February 16, 2023 22:09
@stsewd stsewd force-pushed the refactor-unresolver branch from 9186199 to c505544 Compare February 16, 2023 22:25
@stsewd stsewd marked this pull request as ready for review February 16, 2023 22:29
@stsewd stsewd requested a review from a team as a code owner February 16, 2023 22:29
@stsewd stsewd requested a review from humitos February 16, 2023 22:29
@stsewd stsewd mentioned this pull request Feb 16, 2023
@stsewd
Copy link
Member Author

stsewd commented Feb 22, 2023

This is ready for review.

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

These refactors are making the Proxito code better and better 💯

I left some comments to chat a little more about them and know if I'm understanding everything correctly here. Other than that, I think it's pretty close to be merged.

Comment on lines +195 to +199
# We don't call unparse() on the path,
# since it could be parsed as a full URL if it starts with a protocol.
parsed_url = ParseResult(
scheme="", netloc="", path=path, params="", query="", fragment=""
)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we validate that path comes in the exact shape we require here?

Copy link
Member Author

@stsewd stsewd Feb 22, 2023

Choose a reason for hiding this comment

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

Not sure if I understand what you mean with shape, anything can be a path, this is the path as we receive it from proxito.

Copy link
Member

@humitos humitos Feb 28, 2023

Choose a reason for hiding this comment

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

We are expecting a string with a particular structure. For example, it can't be https://humitos.dev/page/, it has to be just /page/. I'm saying that we should validate the path to be what we expect to be instead of a random string.

Copy link
Member Author

Choose a reason for hiding this comment

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

what we expect is a random string

Copy link
Member

Choose a reason for hiding this comment

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

In the code comment you said that it should not start with a protocol, tho. I'm confused what are the correct values for path then. Can you expand on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment says we can't use unparse() because the path could start with a protocol, or anything really that can confuse unparse() so we manually build the ParseResult class.

Copy link
Member

@humitos humitos Mar 1, 2023

Choose a reason for hiding this comment

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

Yeah, I got that. I'm not saying we have to use unparse(). I'm saying that we can validate the string to be exactly in the shape we need to be and raise an exception otherwise.

:returns: None or a tuple with the current project, version and file.
A tuple with only the project means we weren't able to find a version,
but the translation was correct.
:returns: A tuple with the current project, version and file.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be an object? Maybe an Unresolved<Something> object to keep consistency with the other objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for internal usage only, they are always present.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine. Even if it's internal. Using well-known objects makes the code easier to read and follow.

Copy link
Member Author

Choose a reason for hiding this comment

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

This 3 tuple elements is well-defined, I'd avoid creating data classes for every return type, if we have more than 3 things to return, then that would make sense for me.

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This is pretty close. I made some code suggestions to make it more clear and easy to follow/read without having all the context in mind.

@ericholscher ericholscher linked an issue Feb 28, 2023 that may be closed by this pull request
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Thanks for taking my suggestions into consideration 👍🏼 . I'm fine moving forward with this PR.

@stsewd stsewd merged commit c3e54ba into main Mar 2, 2023
@stsewd stsewd deleted the refactor-unresolver branch March 2, 2023 00: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.

Proxito: Next steps on Improve URL Handling
2 participants