fix: redo the whole caching functionality to make it really 420 blaze it fast #3

Merged
s1d3sw1ped merged 5 commits from fix/blazing-sun-speed into main 2025-07-13 05:21:20 -05:00
2 changed files with 129 additions and 109 deletions
Showing only changes of commit b83836f914 - Show all commits

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)
}