-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_writer.go
49 lines (42 loc) · 1012 Bytes
/
response_writer.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
package TeaGo
import (
"bufio"
"errors"
"net"
"net/http"
)
type responseWriter struct {
responseWriter http.ResponseWriter
status int
bytes int
done bool
}
func newResponseWriter(writer http.ResponseWriter) *responseWriter {
return &responseWriter{
responseWriter: writer,
status: 200,
}
}
func (this *responseWriter) Header() http.Header {
return this.responseWriter.Header()
}
func (this *responseWriter) WriteHeader(status int) {
this.done = true
this.status = status
this.responseWriter.WriteHeader(status)
}
func (this *responseWriter) Write(b []byte) (int, error) {
this.done = true
length, err := this.responseWriter.Write(b)
if err == nil {
this.bytes += length
}
return length, err
}
func (this *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
h, ok := this.responseWriter.(http.Hijacker)
if ok {
return h.Hijack()
}
return nil, nil, errors.New("http.Hijacker not implemented by underlying http.ResponseWriter")
}