@@ -20,99 +20,99 @@ func Test_FromHeadersOrDefault(t *testing.T) {
20
20
}{
21
21
// Without any forwarded headers
22
22
{
23
- "http://localhost:8080/ " ,
23
+ "http://localhost:8080" ,
24
24
"" ,
25
25
"" ,
26
26
"" ,
27
- "http://localhost:8080/ " ,
27
+ "http://localhost:8080" ,
28
28
},
29
29
// With all forwarded headers
30
30
{
31
- "http://localhost:8080/ " ,
31
+ "http://localhost:8080" ,
32
32
"https" ,
33
33
"api.external.host" ,
34
- "/ prefix" ,
34
+ "prefix" ,
35
35
"https://api.external.host/prefix" ,
36
36
},
37
37
// With only forwarded proto
38
38
{
39
- "http://localhost:8080/ " ,
39
+ "http://localhost:8080" ,
40
40
"https" ,
41
41
"" ,
42
42
"" ,
43
- "http://localhost:8080/ " ,
43
+ "http://localhost:8080" ,
44
44
},
45
45
// With only forwarded host
46
46
{
47
- "http://localhost:8080/ " ,
47
+ "http://localhost:8080" ,
48
48
"" ,
49
49
"api.external.host" ,
50
50
"" ,
51
- "https://api.external.host/ " ,
51
+ "https://api.external.host" ,
52
52
},
53
53
// With only forwarded path prefix
54
54
{
55
- "http://localhost:8080/ " ,
55
+ "http://localhost:8080" ,
56
56
"" ,
57
57
"" ,
58
- "/ prefix" ,
58
+ "prefix" ,
59
59
"http://localhost:8080/prefix" ,
60
60
},
61
61
// Without all headers except forwarded proto
62
62
{
63
- "http://localhost:8080/ " ,
63
+ "http://localhost:8080" ,
64
64
"" ,
65
65
"api.external.host" ,
66
- "/ prefix" ,
66
+ "prefix" ,
67
67
"https://api.external.host/prefix" ,
68
68
},
69
69
// Without all headers except forwarded host
70
70
{
71
- "http://localhost:8080/ " ,
71
+ "http://localhost:8080" ,
72
72
"https" ,
73
73
"" ,
74
- "/ prefix" ,
74
+ "prefix" ,
75
75
"http://localhost:8080/prefix" ,
76
76
},
77
77
// Without all headers except forwarded path prefix
78
78
{
79
- "http://localhost:8080/ " ,
79
+ "http://localhost:8080" ,
80
80
"https" ,
81
81
"api.external.host" ,
82
82
"" ,
83
- "https://api.external.host/ " ,
83
+ "https://api.external.host" ,
84
84
},
85
85
// With only forwarded proto and host
86
86
{
87
- "http://localhost:8080/ " ,
87
+ "http://localhost:8080" ,
88
88
"https" ,
89
89
"api.external.host" ,
90
90
"" ,
91
- "https://api.external.host/ " ,
91
+ "https://api.external.host" ,
92
92
},
93
93
// With only forwarded prefix and host
94
94
{
95
- "http://localhost:8080/ " ,
95
+ "http://localhost:8080" ,
96
96
"" ,
97
97
"api.external.host" ,
98
- "/ prefix" ,
98
+ "prefix" ,
99
99
"https://api.external.host/prefix" ,
100
100
},
101
101
// With only forwarded proto and prefix
102
102
{
103
- "http://localhost:8080/ " ,
103
+ "http://localhost:8080" ,
104
104
"https" ,
105
105
"" ,
106
- "/ prefix" ,
106
+ "prefix" ,
107
107
"http://localhost:8080/prefix" ,
108
108
},
109
109
// With non-external forwarded host
110
110
{
111
- "http://localhost:8080/ " ,
111
+ "http://localhost:8080" ,
112
112
"" ,
113
113
"internalhost" ,
114
114
"" ,
115
- "http://localhost:8080/ " ,
115
+ "http://localhost:8080" ,
116
116
},
117
117
}
118
118
@@ -132,41 +132,15 @@ func Test_FromHeadersOrDefault(t *testing.T) {
132
132
}
133
133
134
134
du .JoinPath ()
135
- r := & http.Request {
136
- URL : & url.URL {},
137
- Host : "localhost:8080" ,
138
- Header : h ,
139
- }
140
- builder := FromHeadersOrDefault (r , du )
135
+
136
+ builder := FromHeadersOrDefault (& h , du )
141
137
So (builder , ShouldNotBeNil )
142
138
So (builder .URL , ShouldNotBeNil )
143
139
So (builder .URL .String (), ShouldEqual , tt .want )
144
140
145
141
}
146
142
147
143
})
148
-
149
- Convey ("Given an empty incoming request host" , t , func () {
150
- r := & http.Request {
151
- URL : & url.URL {},
152
- Host : "" ,
153
- }
154
-
155
- Convey ("When the builder is created without forwarded headers" , func () {
156
- defaultURL , err := url .Parse ("http://localhost:8080/" )
157
- So (err , ShouldBeNil )
158
-
159
- builder := FromHeadersOrDefault (r , defaultURL )
160
-
161
- So (builder , ShouldNotBeNil )
162
- So (builder .URL , ShouldNotBeNil )
163
-
164
- Convey ("Then the builder URL should be the default URL" , func () {
165
- So (builder .URL .String (), ShouldEqual , "http://localhost:8080/" )
166
- })
167
- })
168
- })
169
-
170
144
}
171
145
172
146
func TestBuilder_BuildLink (t * testing.T ) {
@@ -179,49 +153,49 @@ func TestBuilder_BuildLink(t *testing.T) {
179
153
}{
180
154
// Empty old link
181
155
{
182
- "http://localhost:8080/ " ,
156
+ "http://localhost:8080" ,
183
157
"" ,
184
- "http://localhost:8080/ " ,
158
+ "http://localhost:8080" ,
185
159
},
186
160
// Old link with no path
187
161
{
188
- "http://localhost:8080/ " ,
189
- "http://localhost:8080/ " ,
190
- "http://localhost:8080/ " ,
162
+ "http://localhost:8080" ,
163
+ "http://localhost:8080" ,
164
+ "http://localhost:8080" ,
191
165
},
192
166
// Old link with different base url
193
167
{
194
- "http://localhost:8080/ " ,
195
- "https://oldHost:1000/ " ,
196
- "http://localhost:8080/ " ,
168
+ "http://localhost:8080" ,
169
+ "https://oldHost:1000" ,
170
+ "http://localhost:8080" ,
197
171
},
198
172
// Old link with path
199
173
{
200
- "http://localhost:8080/ " ,
174
+ "http://localhost:8080" ,
201
175
"http://localhost:8080/some/path" ,
202
176
"http://localhost:8080/some/path" ,
203
177
},
204
178
// Old link with path and different base url
205
179
{
206
- "http://localhost:8080/ " ,
180
+ "http://localhost:8080" ,
207
181
"http://oldHost:1000/some/path" ,
208
182
"http://localhost:8080/some/path" ,
209
183
},
210
184
// Old link without base url
211
185
{
212
- "http://localhost:8080/ " ,
186
+ "http://localhost:8080" ,
213
187
"/some/path" ,
214
188
"http://localhost:8080/some/path" ,
215
189
},
216
190
// Old link with query params
217
191
{
218
- "http://localhost:8080/ " ,
192
+ "http://localhost:8080" ,
219
193
"http://localhost:8080/some/path?param1=value1¶m2=value2" ,
220
194
"http://localhost:8080/some/path?param1=value1¶m2=value2" ,
221
195
},
222
196
// Old external link to new internal url
223
197
{
224
- "http://localhost:8080/ " ,
198
+ "http://localhost:8080" ,
225
199
"https://some.api.host/v1/some/path" ,
226
200
"http://localhost:8080/some/path" ,
227
201
},
@@ -280,21 +254,15 @@ func TestBuilder_BuildLink(t *testing.T) {
280
254
281
255
func Test_FromHeadersOrDefault_NonApiHost (t * testing.T ) {
282
256
Convey ("Given a non-api forwarded host" , t , func () {
283
- defaultURL , err := url .Parse ("http://localhost:8080/ " )
257
+ defaultURL , err := url .Parse ("http://localhost:8080" )
284
258
So (err , ShouldBeNil )
285
259
286
260
h := http.Header {}
287
261
h .Add ("X-Forwarded-Host" , "internalhost" )
288
- h .Add ("X-Forwarded-Path-Prefix" , "/prefix" )
289
-
290
- r := & http.Request {
291
- URL : & url.URL {},
292
- Host : "differenthost:8080" ,
293
- Header : h ,
294
- }
262
+ h .Add ("X-Forwarded-Path-Prefix" , "prefix" )
295
263
296
264
Convey ("When the builder is created" , func () {
297
- builder := FromHeadersOrDefault (r , defaultURL )
265
+ builder := FromHeadersOrDefault (& h , defaultURL )
298
266
299
267
Convey ("Then the builder URL should be the default URL with the path prefix" , func () {
300
268
So (builder , ShouldNotBeNil )
0 commit comments