forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hijack.go
41 lines (35 loc) · 812 Bytes
/
hijack.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
package dotweb
import (
"bufio"
"net"
)
//hijack conn
type HijackConn struct {
ReadWriter *bufio.ReadWriter
Conn net.Conn
header string
}
// WriteString hjiack conn write string
func (hj *HijackConn) WriteString(content string) (int, error) {
n, err := hj.ReadWriter.WriteString(hj.header + "\r\n" + content)
if err == nil {
hj.ReadWriter.Flush()
}
return n, err
}
// WriteBlob hjiack conn write []byte
func (hj *HijackConn) WriteBlob(p []byte) (size int, err error) {
size, err = hj.ReadWriter.Write(p)
if err == nil {
hj.ReadWriter.Flush()
}
return
}
// SetHeader hjiack conn write header
func (hj *HijackConn) SetHeader(key, value string) {
hj.header += key + ": " + value + "\r\n"
}
// Close close hijack conn
func (hj *HijackConn) Close() error {
return hj.Conn.Close()
}