fix: update log message for server startup and improve request handling in ServeHTTP
All checks were successful
PR Check / check-and-test (pull_request) Successful in 1m6s

This commit is contained in:
2025-07-12 09:48:06 -05:00
parent 745856f0f4
commit b83836f914
2 changed files with 129 additions and 109 deletions

View File

@@ -66,7 +66,7 @@ var rootCmd = &cobra.Command{
)
logger.Logger.Info().
Msg("starting SteamCache2 on port 80")
Msg("SteamCache2 listening on port 80")
sc.Run()

View File

@@ -179,6 +179,8 @@ func (sc *SteamCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if strings.HasPrefix(r.URL.String(), "/depot/") {
tstart := time.Now()
cacheKey := strings.ReplaceAll(r.URL.String()[1:], "\\", "/") // replace all backslashes with forward slashes shouldn't be necessary but just in case
@@ -306,4 +308,22 @@ func (sc *SteamCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Int64("size", int64(len(body))).
Dur("duration", time.Since(tstart)).
Msg("request")
return
}
if r.URL.Path == "/favicon.ico" {
w.WriteHeader(http.StatusNoContent)
return
}
if r.URL.Path == "/robots.txt" {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte("User-agent: *\nDisallow: /\n"))
return
}
requestsTotal.WithLabelValues(r.Method, "404").Inc()
logger.Logger.Warn().Str("url", r.URL.String()).Msg("Not found")
http.Error(w, "Not found", http.StatusNotFound)
}