-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtype-message-response.go
65 lines (49 loc) · 1.22 KB
/
type-message-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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import "strings"
func responseFromFile(context *context) (*response, error) {
message, err := messageFromFile(context)
if err != nil {
return nil, err
}
return &response{message}, nil
}
type response struct {
*message
}
func (response *response) Version() string {
return strings.Split(response.FirstLine.Text, " ")[0]
}
func (response *response) StatusCode() string {
return strings.Split(response.FirstLine.Text, " ")[1]
}
func (response *response) ReasonPhrase() string {
return strings.Join(
strings.Split(
response.FirstLine.Text, " ",
)[2:],
" ",
)
}
func (response *response) String() string {
lineStrings := []string{}
lineStrings = append(lineStrings, response.FirstLine.Content())
for _, l := range response.HeaderLines {
content := l.Content()
if content[0:8] == "< Date: " {
content =
content[0:8] +
regexpIdentifier +
regexpIdentifier +
":date" +
regexpIdentifier
}
lineStrings = append(lineStrings, content)
}
lineStrings = append(lineStrings, response.BlankLine.Content())
if response.BodyLines != nil {
for _, l := range response.BodyLines {
lineStrings = append(lineStrings, l.Content())
}
}
return strings.Join(lineStrings, "\n")
}