improved log output

This commit is contained in:
Daniel Sommer 2023-02-02 11:32:55 +01:00
parent 6531080a02
commit 996efe5421

View file

@ -30,7 +30,7 @@ func handleRequests(writer http.ResponseWriter, request *http.Request) {
requestMethod := strings.ToLower(request.Method)
user, authorized := isAuthorized(request)
if !authorized {
log.Debug("denying unauthorized '" + requestMethod + "' request for path '" + requestPath + "'")
log.Info("denying unauthorized '"+requestMethod+"' request", "path: "+requestPath)
writer.WriteHeader(404)
writer.Write([]byte("error: basic authorization failed\n"))
return
@ -38,16 +38,15 @@ func handleRequests(writer http.ResponseWriter, request *http.Request) {
handled := false
switch requestMethod {
case "get":
log.Debug("handling '" + requestMethod + "' request for path '" + requestPath + "'...")
handled = handleGet(user, writer, request)
case "post":
log.Debug("handling '" + requestMethod + "' request for path '" + requestPath + "'...")
handled = handlePost(user, writer, request)
}
if handled {
log.Debug("handled '"+requestMethod+"' request", "path: "+requestPath, "user: "+user)
return
}
log.Debug("ignoring '" + requestMethod + "' request for path '" + requestPath + "'\n")
log.Debug("ignoring '"+requestMethod+"' request", "path: "+requestPath, "user: "+user)
writer.WriteHeader(501)
writer.Write([]byte("error: endpoint '" + requestPath + "' not implemented\n"))
}