@@ -18,7 +18,7 @@ import (
18
18
"github.com/vulcand/oxy/v2/utils"
19
19
)
20
20
21
- func TestSimple (t * testing.T ) {
21
+ func TestBuffer_simple (t * testing.T ) {
22
22
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
23
23
_ , _ = w .Write ([]byte ("hello" ))
24
24
})
@@ -29,7 +29,7 @@ func TestSimple(t *testing.T) {
29
29
30
30
// this is our redirect to server
31
31
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
32
- req .URL = testutils .ParseURI (srv .URL )
32
+ req .URL = testutils .MustParseRequestURI (srv .URL )
33
33
fwd .ServeHTTP (w , req )
34
34
})
35
35
@@ -46,7 +46,7 @@ func TestSimple(t *testing.T) {
46
46
assert .Equal (t , "hello" , string (body ))
47
47
}
48
48
49
- func TestChunkedEncodingSuccess (t * testing.T ) {
49
+ func TestBuffer_chunkedEncodingSuccess (t * testing.T ) {
50
50
var reqBody string
51
51
var contentLength int64
52
52
srv := testutils .NewHandler (func (w http.ResponseWriter , req * http.Request ) {
@@ -63,7 +63,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
63
63
64
64
// this is our redirect to server
65
65
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
66
- req .URL = testutils .ParseURI (srv .URL )
66
+ req .URL = testutils .MustParseRequestURI (srv .URL )
67
67
fwd .ServeHTTP (w , req )
68
68
})
69
69
@@ -74,7 +74,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
74
74
proxy := httptest .NewServer (st )
75
75
t .Cleanup (proxy .Close )
76
76
77
- conn , err := net .Dial ("tcp" , testutils .ParseURI (proxy .URL ).Host )
77
+ conn , err := net .Dial ("tcp" , testutils .MustParseRequestURI (proxy .URL ).Host )
78
78
require .NoError (t , err )
79
79
80
80
_ , _ = fmt .Fprintf (conn , "POST / HTTP/1.1\r \n Host: 127.0.0.1:8080\r \n Transfer-Encoding: chunked\r \n \r \n 4\r \n test\r \n 5\r \n test1\r \n 5\r \n test2\r \n 0\r \n \r \n " )
@@ -86,7 +86,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
86
86
assert .EqualValues (t , len (reqBody ), contentLength )
87
87
}
88
88
89
- func TestChunkedEncodingLimitReached (t * testing.T ) {
89
+ func TestBuffer_chunkedEncodingLimitReached (t * testing.T ) {
90
90
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
91
91
_ , _ = w .Write ([]byte ("hello" ))
92
92
})
@@ -97,7 +97,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
97
97
98
98
// this is our redirect to server
99
99
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
100
- req .URL = testutils .ParseURI (srv .URL )
100
+ req .URL = testutils .MustParseRequestURI (srv .URL )
101
101
fwd .ServeHTTP (w , req )
102
102
})
103
103
@@ -108,7 +108,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
108
108
proxy := httptest .NewServer (st )
109
109
t .Cleanup (proxy .Close )
110
110
111
- conn , err := net .Dial ("tcp" , testutils .ParseURI (proxy .URL ).Host )
111
+ conn , err := net .Dial ("tcp" , testutils .MustParseRequestURI (proxy .URL ).Host )
112
112
require .NoError (t , err )
113
113
_ , _ = fmt .Fprint (conn , "POST / HTTP/1.1\r \n Host: 127.0.0.1:8080\r \n Transfer-Encoding: chunked\r \n \r \n 4\r \n test\r \n 5\r \n test1\r \n 5\r \n test2\r \n 0\r \n \r \n " )
114
114
status , err := bufio .NewReader (conn ).ReadString ('\n' )
@@ -117,7 +117,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
117
117
assert .Equal (t , "HTTP/1.1 413 Request Entity Too Large\r \n " , status )
118
118
}
119
119
120
- func TestChunkedResponse (t * testing.T ) {
120
+ func TestBuffer_chunkedResponse (t * testing.T ) {
121
121
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
122
122
h := w .(http.Hijacker )
123
123
conn , _ , _ := h .Hijack ()
@@ -129,7 +129,7 @@ func TestChunkedResponse(t *testing.T) {
129
129
fwd := forward .New (false )
130
130
131
131
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
132
- req .URL = testutils .ParseURI (srv .URL )
132
+ req .URL = testutils .MustParseRequestURI (srv .URL )
133
133
fwd .ServeHTTP (w , req )
134
134
})
135
135
st , err := New (rdr )
@@ -145,7 +145,7 @@ func TestChunkedResponse(t *testing.T) {
145
145
assert .Equal (t , strconv .Itoa (len ("testtest1test2" )), re .Header .Get ("Content-Length" ))
146
146
}
147
147
148
- func TestRequestLimitReached (t * testing.T ) {
148
+ func TestBuffer_requestLimitReached (t * testing.T ) {
149
149
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
150
150
_ , _ = w .Write ([]byte ("hello" ))
151
151
})
@@ -156,7 +156,7 @@ func TestRequestLimitReached(t *testing.T) {
156
156
157
157
// this is our redirect to server
158
158
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
159
- req .URL = testutils .ParseURI (srv .URL )
159
+ req .URL = testutils .MustParseRequestURI (srv .URL )
160
160
fwd .ServeHTTP (w , req )
161
161
})
162
162
@@ -172,7 +172,7 @@ func TestRequestLimitReached(t *testing.T) {
172
172
assert .Equal (t , http .StatusRequestEntityTooLarge , re .StatusCode )
173
173
}
174
174
175
- func TestResponseLimitReached (t * testing.T ) {
175
+ func TestBuffer_responseLimitReached (t * testing.T ) {
176
176
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
177
177
_ , _ = w .Write ([]byte ("hello, this response is too large" ))
178
178
})
@@ -183,7 +183,7 @@ func TestResponseLimitReached(t *testing.T) {
183
183
184
184
// this is our redirect to server
185
185
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
186
- req .URL = testutils .ParseURI (srv .URL )
186
+ req .URL = testutils .MustParseRequestURI (srv .URL )
187
187
fwd .ServeHTTP (w , req )
188
188
})
189
189
@@ -199,7 +199,7 @@ func TestResponseLimitReached(t *testing.T) {
199
199
assert .Equal (t , http .StatusInternalServerError , re .StatusCode )
200
200
}
201
201
202
- func TestFileStreamingResponse (t * testing.T ) {
202
+ func TestBuffer_fileStreamingResponse (t * testing.T ) {
203
203
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
204
204
_ , _ = w .Write ([]byte ("hello, this response is too large to fit in memory" ))
205
205
})
@@ -210,7 +210,7 @@ func TestFileStreamingResponse(t *testing.T) {
210
210
211
211
// this is our redirect to server
212
212
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
213
- req .URL = testutils .ParseURI (srv .URL )
213
+ req .URL = testutils .MustParseRequestURI (srv .URL )
214
214
fwd .ServeHTTP (w , req )
215
215
})
216
216
@@ -227,7 +227,7 @@ func TestFileStreamingResponse(t *testing.T) {
227
227
assert .Equal (t , "hello, this response is too large to fit in memory" , string (body ))
228
228
}
229
229
230
- func TestCustomErrorHandler (t * testing.T ) {
230
+ func TestBuffer_customErrorHandler (t * testing.T ) {
231
231
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
232
232
_ , _ = w .Write ([]byte ("hello, this response is too large" ))
233
233
})
@@ -238,7 +238,7 @@ func TestCustomErrorHandler(t *testing.T) {
238
238
239
239
// this is our redirect to server
240
240
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
241
- req .URL = testutils .ParseURI (srv .URL )
241
+ req .URL = testutils .MustParseRequestURI (srv .URL )
242
242
fwd .ServeHTTP (w , req )
243
243
})
244
244
@@ -258,7 +258,7 @@ func TestCustomErrorHandler(t *testing.T) {
258
258
assert .Equal (t , http .StatusTeapot , re .StatusCode )
259
259
}
260
260
261
- func TestNotModified (t * testing.T ) {
261
+ func TestBuffer_notModified (t * testing.T ) {
262
262
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
263
263
w .WriteHeader (http .StatusNotModified )
264
264
})
@@ -269,7 +269,7 @@ func TestNotModified(t *testing.T) {
269
269
270
270
// this is our redirect to server
271
271
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
272
- req .URL = testutils .ParseURI (srv .URL )
272
+ req .URL = testutils .MustParseRequestURI (srv .URL )
273
273
fwd .ServeHTTP (w , req )
274
274
})
275
275
@@ -285,7 +285,7 @@ func TestNotModified(t *testing.T) {
285
285
assert .Equal (t , http .StatusNotModified , re .StatusCode )
286
286
}
287
287
288
- func TestNoBody (t * testing.T ) {
288
+ func TestBuffer_noBody (t * testing.T ) {
289
289
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
290
290
w .WriteHeader (http .StatusOK )
291
291
})
@@ -296,7 +296,7 @@ func TestNoBody(t *testing.T) {
296
296
297
297
// this is our redirect to server
298
298
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
299
- req .URL = testutils .ParseURI (srv .URL )
299
+ req .URL = testutils .MustParseRequestURI (srv .URL )
300
300
fwd .ServeHTTP (w , req )
301
301
})
302
302
@@ -313,7 +313,7 @@ func TestNoBody(t *testing.T) {
313
313
}
314
314
315
315
// Make sure that stream handler preserves TLS settings.
316
- func TestPreservesTLS (t * testing.T ) {
316
+ func TestBuffer_preservesTLS (t * testing.T ) {
317
317
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
318
318
w .WriteHeader (http .StatusOK )
319
319
_ , _ = w .Write ([]byte ("ok" ))
@@ -327,7 +327,7 @@ func TestPreservesTLS(t *testing.T) {
327
327
// this is our redirect to server
328
328
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
329
329
cs = req .TLS
330
- req .URL = testutils .ParseURI (srv .URL )
330
+ req .URL = testutils .MustParseRequestURI (srv .URL )
331
331
fwd .ServeHTTP (w , req )
332
332
})
333
333
@@ -345,7 +345,7 @@ func TestPreservesTLS(t *testing.T) {
345
345
assert .NotNil (t , cs )
346
346
}
347
347
348
- func TestNotNilBody (t * testing.T ) {
348
+ func TestBuffer_notNilBody (t * testing.T ) {
349
349
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
350
350
_ , _ = w .Write ([]byte ("hello" ))
351
351
})
@@ -356,7 +356,7 @@ func TestNotNilBody(t *testing.T) {
356
356
357
357
// this is our redirect to server
358
358
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
359
- req .URL = testutils .ParseURI (srv .URL )
359
+ req .URL = testutils .MustParseRequestURI (srv .URL )
360
360
// During a request check if the request body is no nil before sending to the next middleware
361
361
// Because we can send a POST request without body
362
362
assert .NotNil (t , req .Body )
@@ -381,7 +381,7 @@ func TestNotNilBody(t *testing.T) {
381
381
assert .Equal (t , "hello" , string (body ))
382
382
}
383
383
384
- func TestGRPCErrorResponse (t * testing.T ) {
384
+ func TestBuffer_GRPC_ErrorResponse (t * testing.T ) {
385
385
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
386
386
w .Header ().Set ("Grpc-Status" , "10" /* ABORTED */ )
387
387
w .WriteHeader (http .StatusOK )
@@ -396,7 +396,7 @@ func TestGRPCErrorResponse(t *testing.T) {
396
396
397
397
// this is our redirect to server
398
398
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
399
- req .URL = testutils .ParseURI (srv .URL )
399
+ req .URL = testutils .MustParseRequestURI (srv .URL )
400
400
fwd .ServeHTTP (w , req )
401
401
})
402
402
@@ -413,7 +413,7 @@ func TestGRPCErrorResponse(t *testing.T) {
413
413
assert .Empty (t , body )
414
414
}
415
415
416
- func TestGRPCOKResponse (t * testing.T ) {
416
+ func TestBuffer_GRPC_OKResponse (t * testing.T ) {
417
417
srv := testutils .NewHandler (func (w http.ResponseWriter , _ * http.Request ) {
418
418
w .Header ().Set ("Grpc-Status" , "0" /* OK */ )
419
419
_ , _ = w .Write ([]byte ("grpc-body" ))
@@ -429,7 +429,7 @@ func TestGRPCOKResponse(t *testing.T) {
429
429
430
430
// this is our redirect to server
431
431
rdr := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
432
- req .URL = testutils .ParseURI (srv .URL )
432
+ req .URL = testutils .MustParseRequestURI (srv .URL )
433
433
fwd .ServeHTTP (w , req )
434
434
})
435
435
0 commit comments