-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreading.go
More file actions
121 lines (95 loc) · 2.59 KB
/
reading.go
File metadata and controls
121 lines (95 loc) · 2.59 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package regn
import (
"bytes"
"strings"
)
type headStruct struct {
theBuffer []byte
bufferSize int
position int
}
type ResponseType struct {
Header *headStruct
}
func (RES *ResponseType) Close() {
RES.Header.theBuffer = nil
RES.Header.bufferSize = 0
RES.Header.position = 0
}
func (RES *ResponseType) Reset() {
RES.Header.position = 0
RES.Header.theBuffer = RES.Header.theBuffer[:RES.Header.bufferSize]
for xo := 0; xo != RES.Header.bufferSize; xo++ {
RES.Header.theBuffer[xo] = 0x00
}
}
func Response(bufferSize int) *ResponseType {
return &ResponseType{Header: &headStruct{theBuffer: make([]byte, 0, bufferSize), bufferSize: bufferSize}}
}
func (RES *ResponseType) StatusCode() []byte {
index1 := bytes.IndexByte(RES.Header.theBuffer[:RES.Header.position], ' ')
if index1 == -1 {
return nil
}
index2 := index1 + 1 + bytes.IndexByte(RES.Header.theBuffer[index1+1:RES.Header.position], ' ')
if index2 == -1 {
return nil
}
return RES.Header.theBuffer[index1+1 : index2]
}
func (RES *ResponseType) StatusCodeString() string {
return string(RES.StatusCode())
}
func (RES *ResponseType) StatusCodeInt() int {
return BytesToInt(RES.StatusCode())
}
func (RES *ResponseType) Reason() []byte {
index1 := bytes.IndexByte(RES.Header.theBuffer[:RES.Header.position], ' ')
if index1 == -1 {
return nil
}
return RES.Header.theBuffer[index1+1 : bytes.Index(RES.Header.theBuffer, line)]
}
func (RES *ResponseType) ReasonString() string {
return string(RES.Reason())
}
func (RES *ResponseType) Body() []byte {
idx := bytes.Index(RES.Header.theBuffer[:RES.Header.position], lines)
if idx == -1 {
return nil
}
return RES.Header.theBuffer[idx+4 : RES.Header.position]
}
func (RES *ResponseType) BodyString() string {
return string(RES.Body())
}
func (HEAD *headStruct) GetAll() map[string]string {
forReturn := make(map[string]string)
forNothing := strings.Split(string(HEAD.theBuffer[:HEAD.position]), "\r\n")[1:]
for _, res := range forNothing {
index1 := strings.Index(res, ": ")
if index1 == -1 {
break
}
forReturn[res[:index1]] = res[index1+2:]
}
return forReturn
}
func (HEAD *headStruct) Get(name string) string {
forNothing := strings.Split(string(HEAD.theBuffer[:HEAD.position]), "\r\n")[1:]
for _, res := range forNothing {
index1 := strings.Index(res, ": ")
if index1 == -1 {
break
} else if res[:index1] == name {
return res[index1+2:]
}
}
return ""
}
func (RES *ResponseType) Raw() []byte {
return RES.Header.theBuffer[:RES.Header.position]
}
func (RES *ResponseType) RawString() string {
return string(RES.Header.theBuffer[:RES.Header.position])
}