commit 07e69ce08561e1b300dd4b2eecc286b6f5179e3b
parent 856605c4048e47d05d4bcb583ed06c5f8cc36d28
Author: ms <ms@taler.net>
Date: Wed, 13 Oct 2021 12:04:23 +0200
fix URL concatenation
Diffstat:
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -894,12 +894,10 @@ val nexusApp: Application.() -> Unit = {
FacadeShowInfo(
name = f.facadeName,
type = f.type,
- baseUrl = call.url {
- parameters.clear()
- encodedPath = call.request.getBaseUrl()
+ baseUrl = URLBuilder(call.request.getBaseUrl()).apply {
pathComponents("facades", f.facadeName, f.type)
encodedPath += "/"
- },
+ }.buildString(),
config = getFacadeState(f.type, f)
)
}
@@ -921,12 +919,10 @@ val nexusApp: Application.() -> Unit = {
FacadeShowInfo(
name = it.facadeName,
type = it.type,
- baseUrl = call.url {
- parameters.clear()
- encodedPath = call.request.getBaseUrl()
+ baseUrl = URLBuilder(call.request.getBaseUrl()).apply {
pathComponents("facades", it.facadeName, it.type)
encodedPath += "/"
- },
+ }.buildString(),
config = getFacadeState(it.type, it)
)
)
diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt
@@ -45,13 +45,17 @@ private fun internalServerError(
ec = libeufinErrorCode
)
}
+
/**
* Get the base URL of a request; handles proxied case.
*/
fun ApplicationRequest.getBaseUrl(): String {
-
- val isProxied = this.headers.contains("X-Forwarded-Host")
- return if (isProxied) {
+ return if (this.headers.contains("X-Forwarded-Host")) {
+ logger.info("Building X-Forwarded- base URL")
+ var prefix: String = this.headers.get("X-Forwarded-Prefix")
+ ?: throw internalServerError("Reverse proxy did not define X-Forwarded-Prefix")
+ if (!prefix.endsWith("/"))
+ prefix += "/"
URLBuilder(
protocol = URLProtocol(
name = this.headers.get("X-Forwarded-Proto") ?: throw internalServerError("Reverse proxy did not define X-Forwarded-Proto"),
@@ -60,10 +64,12 @@ fun ApplicationRequest.getBaseUrl(): String {
host = this.headers.get("X-Forwarded-Host") ?: throw internalServerError(
"Reverse proxy did not define X-Forwarded-Host"
),
- encodedPath = this.headers.get("X-Forwarded-Prefix") ?: throw internalServerError(
- "Reverse proxy did not define X-Forwarded-Prefix"
- )
- ).toString()
+ encodedPath = prefix
+ ).apply {
+ // Gets dropped otherwise.
+ if (!encodedPath.endsWith("/"))
+ encodedPath += "/"
+ }.buildString()
} else {
this.call.url {
parameters.clear()