-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor CORS handling into injectable components #12982
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
Open
sdelamo
wants to merge
20
commits into
5.3.x
Choose a base branch
from
extract-cors-apis-52x
base: 5.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9dde828
Refactor CORS handling into injectable components
sdelamo 6127259
Update CORS method version annotation from 5.4.0 to 5.2.0
sdelamo 35c0c69
Update CORS filter configuration version in comments
sdelamo ef3f00c
Refactor private network header handling in CORS
sdelamo 35fd9fb
Use Stream.toList()
sdelamo 89dd3f0
Fail deprecated CORS response mutators
sdelamo 26e4274
Fix private network CORS request header
sdelamo 1f3bf32
correct since
sdelamo 6cc7368
Restore CorsFilter response customization hooks
sdelamo b8d2ef4
Merge branch '5.2.x' into extract-cors-apis-52x
sdelamo dc91575
fix merge
sdelamo abdfebf
remove merge test
sdelamo 955ed47
Make default CORS components final
sdelamo 376917d
don’t use optionals
sdelamo 9f36cc6
make it package private
sdelamo c4dc07e
fix checkstyle
sdelamo 781aa40
remove unnecessary checks
sdelamo 48a73d5
make it package private
sdelamo 8af25ff
Restrict CrossOriginUtil internal API visibility
sdelamo d71c402
add docs
sdelamo 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -904,10 +904,32 @@ public static class CorsConfiguration implements Toggleable { | |
| private @Nullable CrossOriginEmbedderPolicy crossOriginEmbedderPolicy; | ||
| private @Nullable CrossOriginResourcePolicy crossOriginResourcePolicy; | ||
|
|
||
| private CorsFilterConfiguration filter = new CorsFilterConfiguration(); | ||
|
|
||
| private Map<String, CorsOriginConfiguration> configurations = Collections.emptyMap(); | ||
|
|
||
| private final Map<String, CorsOriginConfiguration> defaultConfiguration = new LinkedHashMap<>(1); | ||
|
|
||
| /** | ||
| * Returns the CORS filter configuration. | ||
| * | ||
| * @return The CORS filter configuration | ||
| * @since 5.4.0 | ||
| */ | ||
| public CorsFilterConfiguration getFilter() { | ||
| return filter; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the CORS filter configuration. | ||
| * | ||
| * @param filter The CORS filter configuration | ||
| * @since 5.4.0 | ||
|
sdelamo marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public void setFilter(CorsFilterConfiguration filter) { | ||
| this.filter = filter; | ||
| } | ||
|
|
||
| /** | ||
| * @return Whether cors is enabled. Defaults to false. | ||
| */ | ||
|
|
@@ -1016,6 +1038,45 @@ public void setCrossOriginEmbedderPolicy(@Nullable CrossOriginEmbedderPolicy cro | |
| public void setCrossOriginResourcePolicy(@Nullable CrossOriginResourcePolicy crossOriginResourcePolicy) { | ||
| this.crossOriginResourcePolicy = crossOriginResourcePolicy; | ||
| } | ||
|
|
||
| /** | ||
| * Configuration for enabling or disabling the CORS server filter. | ||
| * | ||
| * <p>Disabling the filter disables all server-side CORS processing, including rules | ||
| * declared with {@link io.micronaut.http.server.cors.CrossOrigin}. This differs from | ||
| * {@link CorsConfiguration#isEnabled()}, which controls server-wide CORS | ||
| * configurations but still permits route-level CORS annotations.</p> | ||
| * | ||
| * @since 5.4.0 | ||
| */ | ||
| @ConfigurationProperties("filter") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the namespace here just "filter" and not "cors-filter"? |
||
| public static class CorsFilterConfiguration implements Toggleable { | ||
| /** | ||
| * Whether the CORS server filter is enabled by default. | ||
| */ | ||
| public static final boolean DEFAULT_ENABLED = true; | ||
|
|
||
| private boolean enabled = DEFAULT_ENABLED; | ||
|
|
||
| /** | ||
| * Returns whether the CORS server filter is enabled. | ||
| * | ||
| * @return {@code true} if the CORS server filter is enabled | ||
| */ | ||
| @Override | ||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether the CORS server filter is enabled. | ||
| * | ||
| * @param enabled {@code true} to enable the CORS server filter | ||
| */ | ||
| public void setEnabled(boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.