Fix more potential superfluous header errors.
Make sure we early exit out of the phrase route after pushing a not modified header.
This commit is contained in:
parent
f7720575d5
commit
533c4ca56a
14
routes.go
14
routes.go
|
@ -237,7 +237,7 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
}
|
}
|
||||||
|
|
||||||
var plist map[string]string
|
var plist map[string]string
|
||||||
var doneHead = false
|
var notModified = false
|
||||||
var posLoop = func(positive string) c.RouteError {
|
var posLoop = func(positive string) c.RouteError {
|
||||||
// ! Constrain it to a subset of phrases for now
|
// ! Constrain it to a subset of phrases for now
|
||||||
for _, item := range phraseWhitelist {
|
for _, item := range phraseWhitelist {
|
||||||
|
@ -250,9 +250,8 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
ok = true
|
ok = true
|
||||||
w.Header().Set("ETag", etag)
|
w.Header().Set("ETag", etag)
|
||||||
match := r.Header.Get("If-None-Match")
|
match := r.Header.Get("If-None-Match")
|
||||||
if match != "" && !doneHead && strings.Contains(match, etag) {
|
if match != "" && strings.Contains(match, etag) {
|
||||||
w.WriteHeader(http.StatusNotModified)
|
notModified = true
|
||||||
doneHead = true
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,6 +272,9 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
return rerr
|
return rerr
|
||||||
}
|
}
|
||||||
|
if notModified {
|
||||||
|
break
|
||||||
|
}
|
||||||
pPhrases, ok := phrases.GetTmplPhrasesByPrefix(positive)
|
pPhrases, ok := phrases.GetTmplPhrasesByPrefix(positive)
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.PreErrorJS("No such prefix", w, r)
|
return c.PreErrorJS("No such prefix", w, r)
|
||||||
|
@ -292,6 +294,10 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
}
|
}
|
||||||
plist = pPhrases
|
plist = pPhrases
|
||||||
}
|
}
|
||||||
|
if notModified {
|
||||||
|
w.WriteHeader(http.StatusNotModified)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, negation := range negations {
|
for _, negation := range negations {
|
||||||
for name, _ := range plist {
|
for name, _ := range plist {
|
||||||
|
|
Loading…
Reference in New Issue