-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.go
More file actions
51 lines (40 loc) · 841 Bytes
/
writer.go
File metadata and controls
51 lines (40 loc) · 841 Bytes
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
package httpsig
import (
"bytes"
"net/textproto"
"strings"
)
type writer struct {
bytes.Buffer
headers *[]string
}
func (w *writer) write(name string, values ...string) {
var validValues []string
for _, value := range values {
value = headerNewlineToSpace.Replace(value)
value = textproto.TrimString(value)
if value != "" {
validValues = append(validValues, value)
}
}
if len(validValues) == 0 {
return
}
name = strings.ToLower(name)
if w.headers == nil {
w.headers = &[]string{}
}
*w.headers = append(*w.headers, name)
// the signature lines are, well, lines
if w.Len() > 0 {
w.WriteByte('\n')
}
w.WriteString(name + ": ")
for i, value := range validValues {
w.WriteString(value)
// each value for the is comma+space separated
if i < len(validValues)-1 {
w.WriteString(", ")
}
}
}