Skip to content

Commit

Permalink
cache release
Browse files Browse the repository at this point in the history
  • Loading branch information
Sianao committed Nov 26, 2024
1 parent 17e5e8c commit 71646d5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions router/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func NewRouter(c *cache.Redis) *mux.Router {
if c.Exists(path) {
r.URL.Path = path
http.FileServer(http.Dir("./cache")).ServeHTTP(w, r)
v, ok := r.Header[http.CanonicalHeaderKey("X-Real-IP")]
if !ok {
v = []string{r.RemoteAddr}
}
length, _ := strconv.Atoi(w.Header().Get("Content-Length"))
service.DefaultLogFormatter(
service.LogFormatterParams{StatusCode: 200,
ErrorMessage: "cache",
ContentLength: humanize.Bytes(uint64(length)), ClientIP: v[0], Method: r.Method, Path: r.URL.Path})
return
}
service.PacketProxy(w, r, address)
Expand All @@ -72,6 +81,15 @@ func NewRouter(c *cache.Redis) *mux.Router {
if c.Exists(path) {
r.URL.Path = path
http.FileServer(http.Dir("./cache")).ServeHTTP(w, r)
v, ok := r.Header[http.CanonicalHeaderKey("X-Real-IP")]
if !ok {
v = []string{r.RemoteAddr}
}
length, _ := strconv.Atoi(w.Header().Get("Content-Length"))
service.DefaultLogFormatter(
service.LogFormatterParams{StatusCode: 200,
ErrorMessage: "cache",
ContentLength: humanize.Bytes(uint64(length)), ClientIP: v[0], Method: r.Method, Path: r.URL.Path})
return
}
service.PacketProxy(w, r, address)
Expand Down

0 comments on commit 71646d5

Please sign in to comment.