From cfbb8d48a22bd8c905b5e247c52a949d73c363be Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 1 Sep 2021 21:14:35 +0100 Subject: FIX: index file can be a CGI and should be executed --- server/src/net/usebox/gemini/server/Response.scala | 2 ++ server/src/net/usebox/gemini/server/Server.scala | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'server/src') diff --git a/server/src/net/usebox/gemini/server/Response.scala b/server/src/net/usebox/gemini/server/Response.scala index edb6cdc..1c2071f 100644 --- a/server/src/net/usebox/gemini/server/Response.scala +++ b/server/src/net/usebox/gemini/server/Response.scala @@ -115,6 +115,8 @@ case class Cgi( "REMOTE_HOST" -> remoteAddr ).toSeq + logger.debug(s"CGI env: $env") + val (status: Int, meta: String, body: String) = { val output = new java.io.ByteArrayOutputStream Try { diff --git a/server/src/net/usebox/gemini/server/Server.scala b/server/src/net/usebox/gemini/server/Server.scala index f402191..a14d829 100644 --- a/server/src/net/usebox/gemini/server/Server.scala +++ b/server/src/net/usebox/gemini/server/Server.scala @@ -104,12 +104,16 @@ case class Server(conf: ServiceConf) { .getDefault() .getPath(root, path) .normalize() - val cgi = vhost.getCgi(resource) + val cgi = vhost + .getCgi(resource) match { + case None => vhost.getCgi(resource.resolve(vhost.indexFile)) + case cgi => cgi + } logger.debug(s"requesting: '$resource', cgi is '$cgi'") resource.toFile() match { - case file + case _ if cgi .map(_.toFile()) .map(f => f.isFile() && f.canExecute()) @@ -120,7 +124,7 @@ case class Server(conf: ServiceConf) { val queryString = if (uri.getQuery() == null) "" else uri.getQuery() val pathInfo = - if (cgiFile.compareTo(resource) == 0) "" + if (cgiFile.compareTo(resource) >= 0) "" else "/" + resource .subpath( -- cgit v1.2.3