fixed wrong status for unauhtorized and log it

This commit is contained in:
2026-05-05 13:19:55 -06:00
parent 1c13112255
commit c4ceb7c3f4
2 changed files with 16 additions and 7 deletions
+5 -6
View File
@@ -1,16 +1,15 @@
- Add better logging for errors, filename more deatail
- ~package main~
- ~internal/cache~
- api endpoint to change level
- implement streaming
- Complete testing - Complete testing
- Deployment(PKGBUILD, bootstrap script?) - Deployment(PKGBUILD, bootstrap script?)
- More complete sync(refresh packages on schedule with db, prefetch updates to pkgs we already have) - More complete sync(refresh packages on schedule with db, prefetch updates to pkgs we already have)
- clean cache of old files - clean cache of old files
- implement streaming
- Add chi for mux - Add chi for mux
- Build server/tool - Build server/tool
- Think about: arch doesn't like partial upgrades, round robin fetching the db files might be an issue - Think about: arch doesn't like partial upgrades, round robin fetching the db files might be an issue
- ~Add better logging for errors, filename more deatail~
- ~package main~
- ~internal/cache~
- ~api endpoint to change level~
- ~retry on failed fetch~ - ~retry on failed fetch~
- ~Solve timeout issue large pkgs~ - ~Solve timeout issue large pkgs~
- ~Move project to github as primary~ - ~Move project to github as primary~
+11 -1
View File
@@ -9,7 +9,12 @@ import (
func (s *Server) handlerRefresh(w http.ResponseWriter, req *http.Request) { func (s *Server) handlerRefresh(w http.ResponseWriter, req *http.Request) {
if req.Header.Get("Authorization") != "Bearer "+s.cfg.Auth.Token { if req.Header.Get("Authorization") != "Bearer "+s.cfg.Auth.Token {
http.Error(w, "unauthorized", http.StatusInternalServerError) ip := req.Header.Get("X-Real-IP")
if ip == "" {
ip = req.RemoteAddr
}
slog.Warn("unauthorized request", "ip", ip, "path", req.URL.Path, "method", req.Method)
respondWithError(w, http.StatusUnauthorized, "unauthorized")
return return
} }
defer req.Body.Close() defer req.Body.Close()
@@ -24,6 +29,11 @@ func (s *Server) handlerRefresh(w http.ResponseWriter, req *http.Request) {
func (s *Server) handlerLogLevel(w http.ResponseWriter, req *http.Request) { func (s *Server) handlerLogLevel(w http.ResponseWriter, req *http.Request) {
if req.Header.Get("Authorization") != "Bearer "+s.cfg.Auth.Token { if req.Header.Get("Authorization") != "Bearer "+s.cfg.Auth.Token {
ip := req.Header.Get("X-Real-IP")
if ip == "" {
ip = req.RemoteAddr
}
slog.Warn("unauthorized request", "ip", ip, "path", req.URL.Path, "method", req.Method)
respondWithError(w, http.StatusUnauthorized, "unauthorized") respondWithError(w, http.StatusUnauthorized, "unauthorized")
return return
} }