-
Notifications
You must be signed in to change notification settings - Fork 2
/
http.go
46 lines (37 loc) · 842 Bytes
/
http.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
package websocket
import (
"bytes"
"io"
"net/http"
)
type httpBodyBuffer struct {
bytes.Buffer
}
func (hbb *httpBodyBuffer) Close() error {
return nil
}
type httpResponseWriter struct {
rsp http.Response
body httpBodyBuffer
}
func newHtttpResponseWriter() *httpResponseWriter {
hrw := new(httpResponseWriter)
hrw.rsp.ProtoMajor = 1
hrw.rsp.ProtoMinor = 1
hrw.rsp.Header = make(http.Header)
hrw.rsp.Body = &hrw.body
return hrw
}
func (hrw *httpResponseWriter) Header() http.Header {
return hrw.rsp.Header
}
func (hrw *httpResponseWriter) WriteHeader(status int) {
hrw.rsp.StatusCode = status
}
func (hrw *httpResponseWriter) Write(b []byte) (int, error) {
return hrw.body.Write(b)
}
func (hrw *httpResponseWriter) WriteTo(w io.Writer) error {
hrw.rsp.ContentLength = int64(hrw.body.Len())
return hrw.rsp.Write(w)
}