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