Skip to content

Commit 5da8047

Browse files
authored
superfluous response.WriteHeader warning for Gzip (#1305)
* use traditional gzip compression * rollback gorilla mux * add dedicated http status
1 parent c0e57d3 commit 5da8047

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

cmd/flow-collector/main.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,22 @@ func main() {
383383
userApi.StrictSlash(true)
384384
userApi.HandleFunc("/", authenticated(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
385385
handler, exists := userMap[authMode]
386-
statusCode := http.StatusNoContent
387386

388-
if exists {
389-
userResponse := handler(r)
390-
if response, err := json.Marshal(userResponse); err == nil {
391-
statusCode = http.StatusOK
392-
fmt.Fprintf(w, "%s", response)
393-
}
387+
if !exists {
388+
w.WriteHeader(http.StatusNoContent)
389+
return
390+
}
391+
392+
response, err := json.Marshal(handler(r))
393+
394+
if err != nil {
395+
log.Printf("Error /user response: %s", err.Error())
396+
w.WriteHeader(http.StatusInternalServerError)
397+
return
394398
}
395399

396400
w.Header().Set("Content-Type", "application/json")
397-
w.WriteHeader(statusCode)
401+
w.Write(response)
398402
})))
399403

400404
var userLogout = api1.PathPrefix("/logout").Subrouter()

0 commit comments

Comments
 (0)