-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtype-message-response.go
More file actions
65 lines (48 loc) · 1.25 KB
/
type-message-response.go
File metadata and controls
65 lines (48 loc) · 1.25 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
package main
import "strings"
const dateHeaderPrefix = "< Date: "
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 strings.HasPrefix(content, dateHeaderPrefix) {
content =
dateHeaderPrefix +
regexpIdentifier +
regexpIdentifier +
":date" +
regexpIdentifier
}
lineStrings = append(lineStrings, content)
}
lineStrings = append(lineStrings, response.BlankLine.Content())
for _, l := range response.BodyLines {
lineStrings = append(lineStrings, l.Content())
}
return strings.Join(lineStrings, "\n")
}