-
Notifications
You must be signed in to change notification settings - Fork 181
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
Allow async predicate for cors AllowOrigin #478
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a1c742
allow future predicates for allow-origin
PoOnesNerfect 39115d4
fix cors future
PoOnesNerfect d461516
Merge branch 'main' into add-cors-future
PoOnesNerfect ddf0dd5
merge fix
PoOnesNerfect a5422d3
Merge branch 'main' into add-cors-future
PoOnesNerfect 37b8a21
update method name and argument type
PoOnesNerfect e9e3485
remove usage of futures–core
PoOnesNerfect 56682cb
minor updates and add doc comments
PoOnesNerfect 5e87a5f
add test
PoOnesNerfect 2d2d436
update method name to more appropriate one
PoOnesNerfect 508e31c
require async predicate to be clonable
PoOnesNerfect 14e998d
fix docs
PoOnesNerfect 82e11a5
update doc
PoOnesNerfect File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like users would virtually always have to clone the origin
HeaderValue
, so what do you think about changing this to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting point; I've thought about it for a little, and, for now, I'm still leaning towards keeping it as is, for more consistent type signatures.
For most, or all, async predicate use-cases, you would be awaiting on some external state, which requires you to follow the pattern of:
I'm not sure if removing the line
let origin = origin.clone();
is a big lift in dx, when the pattern itself is already pretty verbose.I would rather have the type signatures be consistent with the other allow origin functions.
Also, having
origin
as owned value may make it feel like there are two ways of doing things.For example, this would work fine:
So, users may try to do something like this, which will not compile:
This may give users a hard time with lifetime errors, if they haven't worked much with async closures.
So, I would just like there to be a single way of doing things, although it might be a bit more annoying, which is:
However, I just might be overthinking it too much, when it's just not a big deal, and will just be a better dx.
I don't think my opinion on this is strong, so I will just go with your decision.
If you think this change makes sense, I will make the change and re-request review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting point about captured variables also needing clone. Could you try changing
Fn
toFnOnce + Clone
? I'm pretty sure that then the extra cloning of captured variables can be internalized into the library as one clone of the closure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that works! however, if you want to use
parts
, you still have to clone it before passing it to the future.Should we also just provide
parts
asRequestParts
instead of&RequestParts
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it becomes too costly at that point, and it'd be better to just let the user decide what to pass into the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah for the origin I think it's okay to clone it always, it's extremely likely the user will need it and not that expensive to clone. The
RequestParts
are much more expensive to clone and virtually never needed in full, or even at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.
I've made the updates, and fixed the docs. Please take a look!