Skip to content

Commit

Permalink
Avoid 412 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Mar 4, 2024
1 parent bbf9265 commit e82d9d4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ func main() {
}

router := httprouter.New()
cache := newCache(k)
router.GET("/healthz", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
if c, _ := cache.Load(); c == nil {
w.WriteHeader(500) // wait for cache to warm before accepting requests
}
w.WriteHeader(204)
})

cache := newCache(k)
router.GET("/v1/fobs", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
if wait := r.URL.Query().Get("wait"); wait != "" {
waitDuration, err := time.ParseDuration(wait)
Expand All @@ -45,10 +48,6 @@ func main() {
}

users, hash := cache.Load()
if users == nil {
w.WriteHeader(412)
return
}
if hash != "" && hash == r.Header.Get("If-None-Match") {
w.WriteHeader(304)
return
Expand Down

0 comments on commit e82d9d4

Please sign in to comment.