summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-01-16 00:30:29 +0000
committerJuan J. Martinez <jjm@usebox.net>2022-01-16 00:31:52 +0000
commit4d00bf26798ea328e9483c2140b45cfdd6fafe04 (patch)
treecef0c6a6615079288bb9ed8e3d444cf61da3218a /server/src
parent60d4dce0193fb9d592f2fe065908bfc88da89dff (diff)
downloadspacebeans-4d00bf26798ea328e9483c2140b45cfdd6fafe04.tar.gz
spacebeans-4d00bf26798ea328e9483c2140b45cfdd6fafe04.zip
Removed nulls
Diffstat (limited to 'server/src')
-rw-r--r--server/src/net/usebox/gemini/server/Server.scala6
-rw-r--r--server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala6
-rw-r--r--server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala6
3 files changed, 8 insertions, 10 deletions
diff --git a/server/src/net/usebox/gemini/server/Server.scala b/server/src/net/usebox/gemini/server/Server.scala
index d474bd3..96cf5ef 100644
--- a/server/src/net/usebox/gemini/server/Server.scala
+++ b/server/src/net/usebox/gemini/server/Server.scala
@@ -31,9 +31,9 @@ case class Server(conf: ServiceConf) {
def handleReq(req: String, remoteAddr: String): Response =
(for {
uri <- Try(URI.create(req)).toEither
- scheme <- Try(uri.getScheme()).toEither
+ scheme <- Try(Option(uri.getScheme())).toEither
resp <- Try(scheme match {
- case null =>
+ case None =>
logger.debug(s"no scheme")
BadRequest(req)
case _ if uri.getPort() != -1 && uri.getPort() != conf.port =>
@@ -44,7 +44,7 @@ case class Server(conf: ServiceConf) {
s"default port but non default was configured, is a proxy request"
)
ProxyRequestRefused(req)
- case "gemini" =>
+ case Some("gemini") =>
logger.debug(s"gemini request: $req")
geminiHandler.handle(req, uri, remoteAddr)
case _ =>
diff --git a/server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala b/server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala
index b582d55..ad5272c 100644
--- a/server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala
+++ b/server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala
@@ -21,7 +21,7 @@ class GeminiHandler(conf: ServiceConf) extends ProtocolHandler(conf) {
case (host, _, None) =>
logger.debug(s"vhost $host not found in $vHosts")
ProxyRequestRefused(req)
- case (host, _, _) if uri.getUserInfo() != null =>
+ case (host, _, _) if Option(uri.getUserInfo()).isDefined =>
logger.debug(s"user info present")
BadRequest(req, "Userinfo component is not allowed")
case (_, path, _) if !path.isValidPath =>
@@ -54,8 +54,7 @@ class GeminiHandler(conf: ServiceConf) extends ProtocolHandler(conf) {
logger.debug("is cgi, will execute")
val cgiFile = cgi.get
- val queryString =
- if (uri.getQuery() == null) "" else uri.getQuery()
+ val queryString = Option(uri.getQuery()).getOrElse("")
val pathInfo =
if (cgiFile.compareTo(resource) >= 0) ""
else
@@ -125,5 +124,4 @@ class GeminiHandler(conf: ServiceConf) extends ProtocolHandler(conf) {
NotFound(req)
}
}
-
}
diff --git a/server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala b/server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala
index f36dc7f..7c85850 100644
--- a/server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala
+++ b/server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala
@@ -17,9 +17,9 @@ abstract class ProtocolHandler(conf: ServiceConf) {
List(".gmi", ".gemini")
.find(path.toString().endsWith(_))
.fold {
- Try(Files.probeContentType(path)).toOption match {
- case Some(mime) if mime != null => mime
- case _ => defaultMimeType
+ Try(Option(Files.probeContentType(path))).toOption.flatten match {
+ case Some(mime) => mime
+ case _ => defaultMimeType
}
}(_ => "text/gemini")
} { types =>