Skip to content

Commit

Permalink
Merge pull request #2093 from MAIF/fix-cors-plugin
Browse files Browse the repository at this point in the history
the wrong cors headers are sending back to the client
  • Loading branch information
Zwiterrion authored Feb 19, 2025
2 parents 0b3f6e7 + 821482e commit f9e68b0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions otoroshi/app/next/plugins/cors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class Cors extends NgRequestTransformer with NgPreRouting {
ctx: NgPreRoutingContext
)(implicit env: Env, ec: ExecutionContext): Future[Either[NgPreRoutingError, Done]] = {
val req = ctx.request
// val cors = CorsSettings.fromJson(ctx.config).getOrElse(CorsSettings()).copy(enabled = true)
val cors = ctx.cachedConfig(internalName)(configReads).getOrElse(NgCorsSettings())

if (req.method == "OPTIONS" && req.headers.get("Access-Control-Request-Method").isDefined) {
// handle cors preflight request
if (cors.legacy.shouldNotPass(req)) {
Expand Down Expand Up @@ -137,9 +137,10 @@ class Cors extends NgRequestTransformer with NgPreRouting {
ctx: NgTransformerResponseContext
)(implicit env: Env, ec: ExecutionContext, mat: Materializer): Either[Result, NgPluginHttpResponse] = {
val req = ctx.request
val cors =
CorsSettings.fromJson(ctx.config).getOrElse(CorsSettings()).copy(enabled = true, excludedPatterns = Seq.empty)
val cors = ctx.cachedConfig(internalName)(configReads).getOrElse(NgCorsSettings())

val corsHeaders = cors
.legacy
.asHeaders(req)
.filter(t => t._1.trim.nonEmpty && t._2.trim.nonEmpty)
.map(v =>
Expand All @@ -166,9 +167,10 @@ class Cors extends NgRequestTransformer with NgPreRouting {
ctx: NgTransformerErrorContext
)(implicit env: Env, ec: ExecutionContext, mat: Materializer): Future[NgPluginHttpResponse] = {
val req = ctx.request
val cors =
CorsSettings.fromJson(ctx.config).getOrElse(CorsSettings()).copy(enabled = true, excludedPatterns = Seq.empty)
val cors = ctx.cachedConfig(internalName)(configReads).getOrElse(NgCorsSettings())

val corsHeaders = cors
.legacy
.asHeaders(req)
.filter(t => t._1.trim.nonEmpty && t._2.trim.nonEmpty)
.map(v =>
Expand Down

0 comments on commit f9e68b0

Please sign in to comment.