This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
header_test.go
147 lines (138 loc) · 6.06 KB
/
header_test.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package rewrite
import (
"net/http"
"testing"
)
func TestHeaderRewriter(t *testing.T) {
defaultHeaderRw := NewHeaderRewriter(func(c *Config) {
c.HeaderPrefix = "Test-"
c.Defmod = NewUrlRewriter("http://a.com", "https://b.tv")
})
cases := []struct {
hrw *HeaderRewriter
in, out map[string]string
}{
{defaultHeaderRw, input, output},
}
for i, c := range cases {
headers := http.Header{}
for key, value := range c.in {
headers.Add(key, value)
}
out := c.hrw.RewriteHeaders(headers)
for key, _ := range out {
value := out.Get(key)
expect := c.out[key]
if expect == "" {
t.Errorf("case %d generated unexpected header: %s, value: %s", i, key, value)
continue
}
if expect != value {
t.Errorf("case %d header: %s, value mismatch. expected: '%s' got: '%s'", i, key, expect, value)
continue
}
}
}
}
var input = map[string]string{
"Access-Control-Allow-Origin": "prefix_if_url_rewrite",
"Access-Control-Allow-Credentials": "prefix_if_url_rewrite",
"Access-Control-Expose-Headers": "prefix_if_url_rewrite",
"Access-Control-Max-Age": "prefix_if_url_rewrite",
"Access-Control-Allow-Methods": "prefix_if_url_rewrite",
"Access-Control-Allow-Headers": "prefix_if_url_rewrite",
"Accept-Patch": "keep",
"Accept-Ranges": "keep",
"Age": "prefix",
"Allow": "keep",
"Alt-Svc": "prefix",
"Cache-Control": "prefix",
"Connection": "prefix",
"Content-Base": "http://a.com/path",
"Content-Disposition": "keep",
"Content-Encoding": "prefix_if_content_rewrite",
"Content-Language": "keep",
"Content-Length": "100",
"Content-Location": "http://a.com/path",
"Content-Md5": "prefix",
"Content-Range": "keep",
"Content-Security-Policy": "prefix",
"Content-Security-Policy-Report-Only": "prefix",
"Content-Type": "keep",
"Date": "keep",
"Etag": "prefix",
"Expires": "prefix",
"Last-Modified": "prefix",
"Link": "keep",
"Location": "http://a.com/path",
"P3p": "prefix",
"Pragma": "prefix",
"Proxy-Authenticate": "keep",
"Public-Key-Pins": "prefix",
"Retry-After": "prefix",
"Server": "prefix",
"Set-Cookie": "cookie",
"Strict-Transport-Security": "prefix",
"Trailer": "prefix",
"Transfer-Encoding": "prefix",
"Tk": "prefix",
"Upgrade": "prefix",
"Upgrade-Insecure-Requests": "prefix",
"Vary": "prefix",
"Via": "prefix",
"Warning": "prefix",
"Www-Authenticate": "keep",
"X-Frame-Options": "prefix",
"X-Xss-Protection": "prefix",
}
var output = map[string]string{
"Test-Access-Control-Allow-Origin": "prefix_if_url_rewrite",
"Test-Access-Control-Allow-Credentials": "prefix_if_url_rewrite",
"Test-Access-Control-Expose-Headers": "prefix_if_url_rewrite",
"Test-Access-Control-Max-Age": "prefix_if_url_rewrite",
"Test-Access-Control-Allow-Methods": "prefix_if_url_rewrite",
"Test-Access-Control-Allow-Headers": "prefix_if_url_rewrite",
"Accept-Patch": "keep",
"Accept-Ranges": "keep",
"Test-Age": "prefix",
"Allow": "keep",
"Test-Alt-Svc": "prefix",
"Test-Cache-Control": "prefix",
"Test-Connection": "prefix",
"Content-Base": "https://b.tv/path",
"Content-Disposition": "keep",
"Content-Encoding": "prefix_if_content_rewrite",
"Content-Language": "keep",
"Content-Length": "100",
"Content-Location": "https://b.tv/path",
"Test-Content-Md5": "prefix",
"Content-Range": "keep",
"Test-Content-Security-Policy": "prefix",
"Test-Content-Security-Policy-Report-Only": "prefix",
"Content-Type": "keep",
"Date": "keep",
"Test-Etag": "prefix",
"Test-Expires": "prefix",
"Test-Last-Modified": "prefix",
"Link": "keep",
"Location": "https://b.tv/path",
"Test-P3p": "prefix",
"Test-Pragma": "prefix",
"Proxy-Authenticate": "keep",
"Test-Public-Key-Pins": "prefix",
"Test-Retry-After": "prefix",
"Test-Server": "prefix",
"Set-Cookie": "cookie",
"Test-Strict-Transport-Security": "prefix",
"Test-Trailer": "prefix",
"Test-Transfer-Encoding": "prefix",
"Test-Tk": "prefix",
"Test-Upgrade": "prefix",
"Test-Upgrade-Insecure-Requests": "prefix",
"Test-Vary": "prefix",
"Test-Via": "prefix",
"Test-Warning": "prefix",
"Www-Authenticate": "keep",
"Test-X-Frame-Options": "prefix",
"Test-X-Xss-Protection": "prefix",
}