// proxyWriter is used to track final status and size of the // response sent to the client type proxyWriter struct { http.ResponseWriter status int size int } func (r *proxyWriter) Header() http.Header { return r.ResponseWriter.Header() } func (r *proxyWriter) Write(b []byte) (int, error) { if r.status == 0 { // default if WriteHeader has not been called yet r.status = http.StatusOK } size, err := r.ResponseWriter.Write(b) r.size += size return size, err } func (r *proxyWriter) WriteHeader(status int) { r.status = status r.ResponseWriter.WriteHeader(status) } func (r *proxyWriter) Status() int { return r.status } func (r *proxyWriter) Size() int { return r.size }