aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-11-24 19:26:43 +0000
committerJuan J. Martinez <jjm@usebox.net>2021-11-24 19:26:43 +0000
commitfc72e681017e4253980ba7943549f6716c959b6a (patch)
tree8a365bb800bf38723700042443dcfb481eeba2b4
parente57871745cb5fd64ab7df4b3c0634e46f6747cd5 (diff)
downloadspacebeans-fc72e681017e4253980ba7943549f6716c959b6a.tar.gz
spacebeans-fc72e681017e4253980ba7943549f6716c959b6a.zip
Fix: host subcompoent in the URL is case insensitive
Referemce: https://datatracker.ietf.org/doc/html/rfc3986/#section-3.2.2
-rw-r--r--CHANGES.md1
-rw-r--r--server/src/net/usebox/gemini/server/Server.scala2
-rw-r--r--server/test/src/ServerSpec.scala24
3 files changed, 26 insertions, 1 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 29e5de4..c185294 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,6 +3,7 @@
### Release 1.4.0 - ????-??-??
- JRE 8 support is deprecated, JRE 11 or later is recommended
+ - Fix: according to RFC 3986, the host subcomponent is case-insensitive. Be aware that this also affects CGIs, and SERVER_NAME will use the value in the configuration.
## Release 1.3.0 - 2021-09-01
diff --git a/server/src/net/usebox/gemini/server/Server.scala b/server/src/net/usebox/gemini/server/Server.scala
index a14d829..ce840df 100644
--- a/server/src/net/usebox/gemini/server/Server.scala
+++ b/server/src/net/usebox/gemini/server/Server.scala
@@ -72,7 +72,7 @@ case class Server(conf: ServiceConf) {
uri.getScheme(),
uri.getHost(),
uri.getPath().decode(),
- vHosts.find(_.host == uri.getHost())
+ vHosts.find(_.host == uri.getHost().toLowerCase)
) match {
case (null, _, _, _) =>
logger.debug(s"no scheme")
diff --git a/server/test/src/ServerSpec.scala b/server/test/src/ServerSpec.scala
index ea40798..c9a6947 100644
--- a/server/test/src/ServerSpec.scala
+++ b/server/test/src/ServerSpec.scala
@@ -152,6 +152,11 @@ class ServerSpec extends AnyFlatSpec with Matchers {
.handleReq("gemini://localhost:8080/", "127.0.0.1") should be(a[Success])
}
+ it should "handle host case insensitive" in {
+ Server(TestData.conf)
+ .handleReq("gemini://LOCALHOST/", "127.0.0.1") should be(a[Success])
+ }
+
it should "return proxy request refused when the vhost is not found" in {
Server(TestData.conf)
.handleReq("gemini://otherhost/", "127.0.0.1") should be(
@@ -461,6 +466,25 @@ class ServerSpec extends AnyFlatSpec with Matchers {
}
}
+ it should "execute a CGI: host is case-insensitive and the value in the conf is used" in {
+ Server(TestData.cgiConf).handleReq(
+ "gemini://LOCALHOST/dir/cgi",
+ "127.0.0.1"
+ ) should matchPattern {
+ case Cgi(
+ _,
+ _,
+ "",
+ "",
+ "cgi",
+ TestData.host,
+ TestData.portStr,
+ _,
+ _
+ ) =>
+ }
+ }
+
it should "execute a CGI: query string" in {
Server(TestData.cgiConf).handleReq(
"gemini://localhost/dir/cgi?query&string",