forked from labstack/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.go
51 lines (42 loc) · 792 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
41
42
43
44
45
46
47
48
49
50
51
package echo
import (
"log"
"net/http"
"github.com/labstack/gommon/color"
)
type (
response struct {
Writer http.ResponseWriter
status int
size int
committed bool
}
)
func (r *response) Header() http.Header {
return r.Writer.Header()
}
func (r *response) WriteHeader(n int) {
if r.committed {
// TODO: Warning
log.Printf("echo: %s", color.Yellow("response already committed"))
return
}
r.status = n
r.Writer.WriteHeader(n)
r.committed = true
}
func (r *response) Write(b []byte) (n int, err error) {
n, err = r.Writer.Write(b)
r.size += n
return n, err
}
func (r *response) Status() int {
return r.status
}
func (r *response) Size() int {
return r.size
}
func (r *response) reset(w http.ResponseWriter) {
r.Writer = w
r.committed = false
}