Github user alficles commented on a diff in the pull request:
https://github.com/apache/incubator-trafficcontrol/pull/425#discussion_r111800861
--- Diff: traffic_monitor_golang/traffic_monitor/datareq/datareq.go ---
@@ -157,16 +159,34 @@ func WrapErrCode(errorCount threadsafe.Uint, reqPath
string, body []byte, err er
// WrapBytes takes a function which cannot error and returns only bytes,
and wraps it as a http.HandlerFunc. The errContext is logged if the write
fails, and should be enough information to trace the problem (function name,
endpoint, request parameters, etc).
func WrapBytes(f func() []byte, contentType string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
+ bytes := f()
+ bytes, err := gzipIfAccepts(r, w, bytes)
+ if err != nil {
+ log.Errorf("gzipping request '%v': %v\n",
r.URL.EscapedPath(), err)
+ code := http.StatusInternalServerError
+ w.WriteHeader(code)
+ if _, err := w.Write([]byte(http.StatusText(code)));
err != nil {
+ log.Warnf("received error writing data request
%v: %v\n", r.URL.EscapedPath(), err)
+ }
+ return
+ }
+
w.Header().Set("Content-Type", contentType)
- log.Write(w, f(), r.URL.EscapedPath())
+ log.Write(w, bytes, r.URL.EscapedPath())
--- End diff --
`log.Write` is a terrible name. It misleads one into thinking that the
purpose of this line is to write to a log at w, not unlike what standard
library functions like [io.WriteString](https://golang.org/pkg/io/#WriteString)
do. Fixing it is probably slightly out of scope... but I register my objection
regardless. :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---