-
Notifications
You must be signed in to change notification settings - Fork 918
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
Add features to allow users specify regular expression or Predicate
for CORS allowed origins
#4982
Conversation
79ec138
to
815cc51
Compare
@minwoox What should happen when users specify WebSocket's allowed origins like below?
Should we throw an exception which specifies it's not possible to set By the way, I've made a test code in |
I think we need to clear this question up before proceeding:
|
Oh, that's a great point. Let's clear below questions first.
I think users might be confused in above situation because even though they received
Returning all or part of the allowed origins from regex matching might be too expensive. In this case(when using regex or predicate for allowed origins), what do you think of returning the origin from the request? By the way, this PR's implementation will simply set |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4982 +/- ##
============================================
+ Coverage 74.09% 74.12% +0.03%
- Complexity 20907 21002 +95
============================================
Files 1809 1819 +10
Lines 76940 77357 +417
Branches 9833 9880 +47
============================================
+ Hits 57005 57341 +336
- Misses 15291 15367 +76
- Partials 4644 4649 +5 ☔ View full report in Codecov by Sentry. |
Oops, you are already doing it correctly. Let me continue to review the PR. 😉 |
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.
Thanks! Looks pretty good. I left some suggestions. 😉
core/src/main/java/com/linecorp/armeria/server/cors/AbstractCorsPolicyBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/AbstractCorsPolicyBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/AbstractCorsPolicyBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsService.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsServiceBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/websocket/WebSocketServiceBuilder.java
Outdated
Show resolved
Hide resolved
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.
Looks good overall! Left a comment on the overall design
core/src/main/java/com/linecorp/armeria/server/cors/CorsDecoratorFactoryFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/AbstractCorsPolicyBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/websocket/DefaultWebSocketService.java
Outdated
Show resolved
Hide resolved
After discussing with the team, we've decided to deprecate the |
core/src/main/java/com/linecorp/armeria/server/annotation/decorator/CorsDecorator.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/AbstractCorsPolicyBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/ChainedCorsPolicyBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsPolicy.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsPolicyBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/websocket/WebSocketServiceBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsServiceBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/cors/CorsService.java
Outdated
Show resolved
Hide resolved
- Allow `CorsDecorator` to accept list of regular expressions - Add `@UnstableApi` annotation - Cache `Collections.singletonList(*)`
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.
👍 👍 👍
Please sign the CLA if you haven't already @seonwoo960000 🙇 |
@jrhee17 thanks for the review. Seems like I've already signed up the CLA as follows |
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.
Thanks, @seonwoo960000! 👍 👍 👍 👍 👍
Can you try modifying the authoring email of your commits so that we can move forward with this PR? |
@jrhee17, thank you for detailed explanation. I've fixed my authoring email address |
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 looks useful. Thanks, @seonwoo960000! 🙇♂️
Motivation:
Allow users to specify CORS allowed origins by regular expression or
Predicate<String>
Modifications:
Users can specify allowed origins by using regular expression or
Predicate<String>
like below.CorsDecorator
CorsService
'sbuilderForOriginRegex
orbuilder(Predicate<String> originPredicate)
or per route
WebSocketServiceBuilder
'sallowedOrigins(Predicate<String> originPredicate>
Result:
Predicate<String>
to specify allowed origins