From 7e15756a687e6dbe6ad1577a839377c13d32cd57 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 19 Feb 2020 15:56:32 -0500 Subject: [PATCH] better logging --- README | 3 +-- server.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README b/README index e0a6de1..78d90cd 100644 --- a/README +++ b/README @@ -2,7 +2,6 @@ SecretShop: a small Gemini server. # Features * Multi-site hosting -* CGI (WIP) * Fully compliant with Jetforce diagnostics * Probably won't kill your computer @@ -22,7 +21,7 @@ localhost: KeyFile: "localhost.key" CertFile: "localhost.crt" - +Please note that CGIDir currently not used (waiting on spec clarification). # Running Either run the executable directly or use the SystemD unit file diff --git a/server.go b/server.go index 6e03613..f97cc87 100644 --- a/server.go +++ b/server.go @@ -123,19 +123,19 @@ func (c *conn) serve(ctx context.Context) { data[count] = b count = count + 1 } + var res Response + var req string if !strings.Contains(string(data), "\r\n") { - c.sendResponse(Response{STATUS_BAD_REQUEST, "Request too large", ""}) - c.C.Close() - return + res = Response{STATUS_BAD_REQUEST, "Request too large", ""} + req = "TOO_LONG_REQUEST" + } else if !utf8.Valid(data) { + res = Response{STATUS_BAD_REQUEST, "URL contains non UTF8 charcaters", ""} + } else { + req = string(data[:count-2]) + res = c.server.ParseRequest(req) } - if !utf8.Valid(data) { - c.sendResponse(Response{STATUS_BAD_REQUEST, "URL contains non UTF8 charcaters", ""}) - c.C.Close() - return - } - req := string(data[:count-2]) - res := c.server.ParseRequest(req) c.sendResponse(res) + log.Printf("%v: %v requested %v; responded with %v %v", c.server.Hostname, c.C.RemoteAddr(), req, res.Status, res.Meta) c.C.Close() }