-
Notifications
You must be signed in to change notification settings - Fork 55
/
header.go
69 lines (55 loc) · 1.55 KB
/
header.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
66
67
68
69
package serverHandler
import (
"mjpclab.dev/ghfs/src/util"
"net/http"
)
type pathHeaders struct {
path string
headers [][2]string
}
func newPathHeaders(pathHeadersList [][]string) []pathHeaders {
results := make([]pathHeaders, 0, len(pathHeadersList))
for _, pathHeadersSeq := range pathHeadersList {
if len(pathHeadersSeq) <= 1 { // no headers
continue
}
refPath := pathHeadersSeq[0]
pathHeadersSeq = pathHeadersSeq[1:]
headerPairCount := len(pathHeadersSeq) / 2
if headerPairCount == 0 {
continue
}
headers := make([][2]string, headerPairCount)
for i := 0; i < headerPairCount; i++ {
headers[i] = [2]string{pathHeadersSeq[i*2], pathHeadersSeq[i*2+1]}
}
results = append(results, pathHeaders{refPath, headers})
}
return results
}
func (h *aliasHandler) getHeaders(reqUrlPath, reqFsPath string, doGetHeaders bool) [][2]string {
if !doGetHeaders {
return nil
}
headers := make([][2]string, len(h.globalHeaders), len(h.globalHeaders)+len(h.headersUrls)+len(h.headersDirs))
if len(h.globalHeaders) > 0 {
copy(headers, h.globalHeaders)
}
for i := range h.headersUrls {
if util.HasUrlPrefixDir(reqUrlPath, h.headersUrls[i].path) {
headers = append(headers, h.headersUrls[i].headers...)
}
}
for i := range h.headersDirs {
if util.HasFsPrefixDir(reqFsPath, h.headersDirs[i].path) {
headers = append(headers, h.headersDirs[i].headers...)
}
}
return headers
}
func header(w http.ResponseWriter, headers [][2]string) {
header := w.Header()
for i := range headers {
header.Add(headers[i][0], headers[i][1])
}
}