From 4d00bf26798ea328e9483c2140b45cfdd6fafe04 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 16 Jan 2022 00:30:29 +0000 Subject: Removed nulls --- server/src/net/usebox/gemini/server/Server.scala | 6 +++--- server/src/net/usebox/gemini/server/handlers/GeminiHandler.scala | 6 ++---- server/src/net/usebox/gemini/server/handlers/ProtocolHandler.scala | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'server/src/net') 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 => -- cgit v1.2.3