github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/response.go (about)

     1  package buffalo
     2  
     3  import (
     4  	"bufio"
     5  	"encoding/binary"
     6  	"net"
     7  	"net/http"
     8  
     9  	"github.com/pkg/errors"
    10  )
    11  
    12  type buffaloResponse struct {
    13  	status int
    14  	size   int
    15  	http.ResponseWriter
    16  }
    17  
    18  func (w *buffaloResponse) WriteHeader(i int) {
    19  	w.status = i
    20  	w.ResponseWriter.WriteHeader(i)
    21  }
    22  
    23  func (w *buffaloResponse) Write(b []byte) (int, error) {
    24  	w.size = binary.Size(b)
    25  	return w.ResponseWriter.Write(b)
    26  }
    27  func (w *buffaloResponse) Hijack() (net.Conn, *bufio.ReadWriter, error) {
    28  	if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
    29  		return hj.Hijack()
    30  	}
    31  	return nil, nil, errors.WithStack(errors.New("does not implement http.Hijack"))
    32  }
    33  
    34  func (w *buffaloResponse) Flush() {
    35  	w.ResponseWriter.(http.Flusher).Flush()
    36  }
    37  
    38  func (w *buffaloResponse) CloseNotify() <-chan bool {
    39  	return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
    40  }