aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-02-26 10:45:00 +0000
committerJuan J. Martinez <jjm@usebox.net>2021-07-22 19:49:48 +0100
commitb2d82bddd39d61c81ce14086809d817a1475e0b5 (patch)
tree0a0e233a2f134abd2da44eece02fc16ffd382dd7 /server
parent2149d073ddb557ad70d2aa0a86289653530e5986 (diff)
downloadspacebeans-b2d82bddd39d61c81ce14086809d817a1475e0b5.tar.gz
spacebeans-b2d82bddd39d61c81ce14086809d817a1475e0b5.zip
Support for JDK 8 (and 11)
Diffstat (limited to 'server')
-rw-r--r--server/src/net/usebox/gemini/server/Server.scala8
-rw-r--r--server/test/src/ServerSpec.scala34
2 files changed, 28 insertions, 14 deletions
diff --git a/server/src/net/usebox/gemini/server/Server.scala b/server/src/net/usebox/gemini/server/Server.scala
index c2fcee3..ed9252d 100644
--- a/server/src/net/usebox/gemini/server/Server.scala
+++ b/server/src/net/usebox/gemini/server/Server.scala
@@ -3,8 +3,7 @@ package net.usebox.gemini.server
import java.nio.charset.Charset
import javax.net.ssl.SSLEngine
import java.net.URI
-import java.nio.file.Path
-import java.nio.file.Files
+import java.nio.file.{Path, FileSystems, Files}
import scala.util.{Try, Success => TrySuccess}
@@ -102,7 +101,10 @@ case class Server(conf: ServiceConf) {
logger.debug("redirect to normalize uri")
PermanentRedirect(req, uri.normalize().toString())
case ("gemini", host, path, Some(vhost)) =>
- val resource = Path.of(vhost.root, path).normalize()
+ val resource = FileSystems
+ .getDefault()
+ .getPath(vhost.root, path)
+ .normalize()
logger.debug(s"requesting: '$resource'")
diff --git a/server/test/src/ServerSpec.scala b/server/test/src/ServerSpec.scala
index 40a2818..d086d2d 100644
--- a/server/test/src/ServerSpec.scala
+++ b/server/test/src/ServerSpec.scala
@@ -1,6 +1,6 @@
package net.usebox.gemini.server
-import java.nio.file.Path
+import java.nio.file.FileSystems
import scala.concurrent.duration._
@@ -33,33 +33,42 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve a known MIME type" in {
Server(TestData.conf)
- .guessMimeType(Path.of("file.html"), None) shouldBe "text/html"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.html"),
+ None
+ ) shouldBe "text/html"
}
it should "resolve de default MIME type for unknown types" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("unknow"),
+ FileSystems.getDefault().getPath("unknow"),
None
) shouldBe TestData.conf.defaultMimeType
}
it should "resolve gemini MIME type" in {
Server(TestData.conf)
- .guessMimeType(Path.of("file.gmi"), None) shouldBe "text/gemini"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gmi"),
+ None
+ ) shouldBe "text/gemini"
Server(TestData.conf)
- .guessMimeType(Path.of("file.gemini"), None) shouldBe "text/gemini"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gemini"),
+ None
+ ) shouldBe "text/gemini"
}
it should "resolve gemini MIME type, including parameters" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some("param")
) shouldBe "text/gemini; param"
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gemini"),
+ FileSystems.getDefault().getPath("file.gemini"),
Some("param")
) shouldBe "text/gemini; param"
}
@@ -67,7 +76,7 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "gemini MIME type parameters are sanitized" in {
Server(TestData.conf)
.guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some(" ; param")
) shouldBe "text/gemini; param"
}
@@ -76,14 +85,17 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve a known MIME type" in {
Server(TestData.conf.copy(mimeTypes = TestData.mimeTypes))
- .guessMimeType(Path.of("file.gmi"), None) shouldBe "config"
+ .guessMimeType(
+ FileSystems.getDefault().getPath("file.gmi"),
+ None
+ ) shouldBe "config"
}
it should "include parameters for text/gemini MIME types" in {
Server(
TestData.conf.copy(mimeTypes = Some(Map("text/gemini" -> List(".gmi"))))
).guessMimeType(
- Path.of("file.gmi"),
+ FileSystems.getDefault().getPath("file.gmi"),
Some("param")
) shouldBe "text/gemini; param"
}
@@ -91,7 +103,7 @@ class ServerSpec extends AnyFlatSpec with Matchers {
it should "resolve de default MIME type for unknown types" in {
Server(TestData.conf.copy(mimeTypes = TestData.mimeTypes))
.guessMimeType(
- Path.of("unknow"),
+ FileSystems.getDefault().getPath("unknow"),
None
) shouldBe TestData.conf.defaultMimeType
}