1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 // ResponseWriter wraps http.ResponseWriter and exposes the status
12 // sent, the number of bytes sent to the client, and the last write
14 type ResponseWriter struct {
16 wroteStatus *int // Last status given to WriteHeader()
17 wroteBodyBytes *int // Bytes successfully written
18 err *error // Last error returned from Write()
21 func WrapResponseWriter(orig http.ResponseWriter) ResponseWriter {
22 return ResponseWriter{orig, new(int), new(int), new(error)}
25 func (w ResponseWriter) WriteHeader(s int) {
27 w.ResponseWriter.WriteHeader(s)
30 func (w ResponseWriter) Write(data []byte) (n int, err error) {
31 n, err = w.ResponseWriter.Write(data)
32 *w.wroteBodyBytes += n
37 func (w ResponseWriter) WroteStatus() int {
41 func (w ResponseWriter) WroteBodyBytes() int {
42 return *w.wroteBodyBytes
45 func (w ResponseWriter) Err() error {