Navigation Menu

Skip to content
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

Router avoid method conflicts #34

Merged

Conversation

fkettelhoit
Copy link
Contributor

Depends on #33

I noticed that I could not add a catchall route /*whatever without causing a conflict with an existing route /something, even if the 2 routes used different HTTP methods. I am not sure whether this is expected behavior, but I thought that it might make sense to check conflicts only for routes with the same HTTP methods, which is what this PR implements.

For example, with this PR it is possible to define a /*whatever route for OPTIONS requests without causing conflicts with any existing and more specific GET route.

@nilslice
Copy link
Contributor

Thanks @fkettelhoit! this is great, and nice catch with the route issue. I'll give this and your other PR a review ASAP.

@nilslice nilslice changed the base branch from main to merge/pr-34 September 13, 2021 17:55
@nilslice nilslice merged commit 2ae3858 into cloudflare:merge/pr-34 Sep 13, 2021
@nilslice
Copy link
Contributor

@fkettelhoit -

testing this on branch merge/pr-34, I observe this panic:

panicked at 'failed to register Options route for /async pattern: Conflict { with: "/async" }', ~/workers-rs/worker/src/router.rs:271:18

Mind taking a look?

@fkettelhoit
Copy link
Contributor Author

I haven't deployed the sandbox worker yet, but shouldn't this be the expected behavior? In line 235 the worker uses an on_async, which will match all methods, including OPTIONS and thus clash with the options_async in line 347.

(Btw I also noticed that the with_status method in this branch uses a Result<Self> signature again, despite your previous commit. Sorry about the signature change btw, you are right that the Self return type makes more sense for mapping responses.)

@nilslice
Copy link
Contributor

I haven't deployed the sandbox worker yet, but shouldn't this be the expected behavior? In line 235 the worker uses an on_async, which will match all methods, including OPTIONS and thus clash with the options_async in line 347.

Ah, yes! thank you. Definitely working as expected 😆

(Btw I also noticed that the with_status method in this branch uses a Result signature again, despite your previous commit. Sorry about the signature change btw, you are right that the Self return type makes more sense for mapping responses.)

Yea I need to rebase this. Thanks! No worries about the signature change.. it's really the right thing to do so we can catch invalid codes.. Do you think it's worth the trade-off? My concern is that it's pretty unlikely that the end-user will defensively attempt to check this error, since Response is generally at the very end of the block... very open to input on it though!

@fkettelhoit
Copy link
Contributor Author

I was initially a bit torn myself, but I agree that choosing Self is the better trade-off. Situations where handling the error instead of panicking makes a difference should be pretty rare and Result<Self> is definitely much more inconvenient to use.

@nilslice
Copy link
Contributor

Ok, cool. Thank you for the feedback. I'll leave it as-is then and we can reconsider later on!

nilslice pushed a commit that referenced this pull request Sep 15, 2021
Merge PR for #34, add or_else_any_method explicit handlers
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.

None yet

2 participants