1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 type ResponseWriter interface {
17 // responseWriter wraps http.ResponseWriter and exposes the status
18 // sent, the number of bytes sent to the client, and the last write
20 type responseWriter struct {
22 wroteStatus int // Last status given to WriteHeader()
23 wroteBodyBytes int // Bytes successfully written
24 err error // Last error returned from Write()
27 func WrapResponseWriter(orig http.ResponseWriter) ResponseWriter {
28 return &responseWriter{ResponseWriter: orig}
31 func (w *responseWriter) CloseNotify() <-chan bool {
32 if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
33 return cn.CloseNotify()
38 func (w *responseWriter) WriteHeader(s int) {
40 w.ResponseWriter.WriteHeader(s)
43 func (w *responseWriter) Write(data []byte) (n int, err error) {
44 if w.wroteStatus == 0 {
45 w.WriteHeader(http.StatusOK)
47 n, err = w.ResponseWriter.Write(data)
53 func (w *responseWriter) WroteStatus() int {
57 func (w *responseWriter) WroteBodyBytes() int {
58 return w.wroteBodyBytes
61 func (w *responseWriter) Err() error {