Skip to content

Commit

Permalink
oops
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Jul 8, 2024
1 parent 8120a43 commit 53ecb8d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions otoroshi/app/next/plugins/headers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ class OverrideLocationHeader extends NgRequestTransformer {
if ((status > 299 && status < 400) || status == 201) {
ctx.otoroshiResponse.header("Location") match {
case None => ctx.otoroshiResponse.right
case Some(location) if location.startsWith("http://") || location.startsWith("https://") => ctx.otoroshiResponse.right
case Some(location) if !(location.startsWith("http://") || location.startsWith("https://")) => ctx.otoroshiResponse.right
case Some(location) => {
val host = TargetExpressionLanguage(
val backendHost = TargetExpressionLanguage(
backend.hostname,
Some(ctx.request),
ctx.route.serviceDescriptor.some,
Expand All @@ -144,9 +144,15 @@ class OverrideLocationHeader extends NgRequestTransformer {
env
)
val oldLocation = Uri(location)
val newLocation = oldLocation.copy(authority = oldLocation.authority.copy(host = Uri.Host(host))).toString()
val headers = ctx.otoroshiResponse.headers.-("Location").-("location").+("Location" -> newLocation)
ctx.otoroshiResponse.copy(headers = headers).right
val oldLocationHost = oldLocation.authority.host.toString()
if (oldLocationHost.equalsIgnoreCase(backendHost)) {
val frontendHost = Option(ctx.request.domain).filterNot(_.isBlank).getOrElse(ctx.route.frontend.domains.head.domain)
val newLocation = oldLocation.copy(authority = oldLocation.authority.copy(host = Uri.Host(frontendHost))).toString()
val headers = ctx.otoroshiResponse.headers.-("Location").-("location").+("Location" -> newLocation)
ctx.otoroshiResponse.copy(headers = headers).right
} else {
ctx.otoroshiResponse.right
}
}
}
} else {
Expand Down

0 comments on commit 53ecb8d

Please sign in to comment.