Skip to content

Commit

Permalink
[cors] Use compiler instead of never reached exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Playacem committed Mar 10, 2024
1 parent 510bd10 commit 12e07b7
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions javalin/src/main/java/io/javalin/plugin/bundled/CorsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,10 @@ class CorsPluginConfig {
require(it != "null") { "Adding the string null as an allowed host is forbidden. Consider calling anyHost() instead" }
require(isValidOrigin(it)) { "The given value '${origins[idx]}' could not be transformed into a valid origin" }
val wildcardResult = originFulfillsWildcardRequirements(it)
require(wildcardResult !is WildcardResult.ErrorState) {
when (wildcardResult) {
WildcardResult.ErrorState.TooManyWildcards -> "Too many wildcards detected inside '${origins[idx]}'. Only one at the start of the host is allowed!"
WildcardResult.ErrorState.WildcardNotAtTheStartOfTheHost -> "The wildcard must be at the start of the passed in host. The value '${origins[idx]}' violates this requirement!"
else -> throw IllegalStateException(
"""This code path should never be hit.
|
|Please report it to the maintainers of Javalin as a GitHub issue at https://github.com/javalin/javalin/issues/new/choose""".trimMargin()
)
}
when (wildcardResult) {
WildcardResult.WildcardOkay, WildcardResult.NoWildcardDetected -> Unit
WildcardResult.ErrorState.TooManyWildcards -> throw IllegalArgumentException("Too many wildcards detected inside '${origins[idx]}'. Only one at the start of the host is allowed!")
WildcardResult.ErrorState.WildcardNotAtTheStartOfTheHost -> throw IllegalArgumentException("The wildcard must be at the start of the passed in host. The value '${origins[idx]}' violates this requirement!")
}
allowedOrigins.add(it)
}
Expand Down

0 comments on commit 12e07b7

Please sign in to comment.