forked from labstack/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
71 lines (61 loc) · 1.17 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package echo
import (
"bufio"
"errors"
"log"
"net"
"net/http"
)
type (
response struct {
http.ResponseWriter
status int
size int
committed bool
}
)
func (r *response) WriteHeader(n int) {
// TODO: fix when halted.
if r.committed {
// TODO: Warning
log.Println("echo: response already committed")
return
}
r.status = n
r.ResponseWriter.WriteHeader(n)
r.committed = true
}
func (r *response) Write(b []byte) (n int, err error) {
n, err = r.ResponseWriter.Write(b)
r.size += n
return n, err
}
func (r *response) CloseNotify() <-chan bool {
cn, ok := r.ResponseWriter.(http.CloseNotifier)
if !ok {
return nil
}
return cn.CloseNotify()
}
func (r *response) Flusher() {
if f, ok := r.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}
func (r *response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
h, ok := r.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("bolt: hijacker interface not supported")
}
return h.Hijack()
}
func (r *response) Status() int {
return r.status
}
func (r *response) Size() int {
return r.size
}
func (r *response) reset(rw http.ResponseWriter) {
r.ResponseWriter = rw
r.committed = false
}