-
Notifications
You must be signed in to change notification settings - Fork 0
/
headers.go
44 lines (35 loc) · 1 KB
/
headers.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
package main
import (
"fmt"
"strings"
)
type Headers map[string]string
func (h Headers) String() string {
// strings.Builder minimizes memory copying for each header value
// which would occur with string concatenation
var headerString strings.Builder
for k, v := range h {
fmt.Fprintf(&headerString, "%s: %s\r\n", k, v)
}
return headerString.String()
}
func DefaultHtmlHeaders() Headers {
headers := make(Headers)
headers["Server"] = "go-http-server"
headers["Content-Type"] = "text/html"
headers["Connection"] = "Keep-Alive"
headers["Keep-Alive"] = "timeout=5, max=997"
headers["Transfer-Encoding"] = "identity"
return headers
}
func PngHeaders() Headers {
headers := make(Headers)
headers["Server"] = "go-http-server"
headers["Content-Type"] = "image/png"
headers["Connection"] = "Keep-Alive"
headers["Keep-Alive"] = "timeout=5, max=997"
headers["Transfer-Encoding"] = "identity"
headers["Content-Transfer-Encoding"] = "binary"
headers["Content-Disposition"] = "inline;"
return headers
}