@@ -216,6 +216,27 @@ func TestRouterChaining(t *testing.T) {
216
216
}
217
217
}
218
218
219
+ func BenchmarkAllowed (b * testing.B ) {
220
+ handlerFunc := func (_ http.ResponseWriter , _ * http.Request , _ Params ) {}
221
+
222
+ router := New ()
223
+ router .POST ("/path" , handlerFunc )
224
+ router .GET ("/path" , handlerFunc )
225
+
226
+ b .Run ("Global" , func (b * testing.B ) {
227
+ b .ReportAllocs ()
228
+ for i := 0 ; i < b .N ; i ++ {
229
+ _ = router .allowed ("*" , http .MethodOptions )
230
+ }
231
+ })
232
+ b .Run ("Path" , func (b * testing.B ) {
233
+ b .ReportAllocs ()
234
+ for i := 0 ; i < b .N ; i ++ {
235
+ _ = router .allowed ("/path" , http .MethodOptions )
236
+ }
237
+ })
238
+ }
239
+
219
240
func TestRouterOPTIONS (t * testing.T ) {
220
241
handlerFunc := func (_ http.ResponseWriter , _ * http.Request , _ Params ) {}
221
242
@@ -229,7 +250,7 @@ func TestRouterOPTIONS(t *testing.T) {
229
250
router .ServeHTTP (w , r )
230
251
if ! (w .Code == http .StatusOK ) {
231
252
t .Errorf ("OPTIONS handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
232
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, OPTIONS " {
253
+ } else if allow := w .Header ().Get ("Allow" ); allow != "OPTIONS, POST " {
233
254
t .Error ("unexpected Allow header value: " + allow )
234
255
}
235
256
@@ -239,7 +260,7 @@ func TestRouterOPTIONS(t *testing.T) {
239
260
router .ServeHTTP (w , r )
240
261
if ! (w .Code == http .StatusOK ) {
241
262
t .Errorf ("OPTIONS handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
242
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, OPTIONS " {
263
+ } else if allow := w .Header ().Get ("Allow" ); allow != "OPTIONS, POST " {
243
264
t .Error ("unexpected Allow header value: " + allow )
244
265
}
245
266
@@ -260,7 +281,7 @@ func TestRouterOPTIONS(t *testing.T) {
260
281
router .ServeHTTP (w , r )
261
282
if ! (w .Code == http .StatusOK ) {
262
283
t .Errorf ("OPTIONS handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
263
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, GET, OPTIONS" && allow != "GET , POST, OPTIONS " {
284
+ } else if allow := w .Header ().Get ("Allow" ); allow != "GET, OPTIONS, POST" {
264
285
t .Error ("unexpected Allow header value: " + allow )
265
286
}
266
287
@@ -270,7 +291,7 @@ func TestRouterOPTIONS(t *testing.T) {
270
291
router .ServeHTTP (w , r )
271
292
if ! (w .Code == http .StatusOK ) {
272
293
t .Errorf ("OPTIONS handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
273
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, GET, OPTIONS" && allow != "GET , POST, OPTIONS " {
294
+ } else if allow := w .Header ().Get ("Allow" ); allow != "GET, OPTIONS, POST" {
274
295
t .Error ("unexpected Allow header value: " + allow )
275
296
}
276
297
@@ -287,7 +308,7 @@ func TestRouterOPTIONS(t *testing.T) {
287
308
router .ServeHTTP (w , r )
288
309
if ! (w .Code == http .StatusOK ) {
289
310
t .Errorf ("OPTIONS handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
290
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, GET, OPTIONS" && allow != "GET , POST, OPTIONS " {
311
+ } else if allow := w .Header ().Get ("Allow" ); allow != "GET, OPTIONS, POST" {
291
312
t .Error ("unexpected Allow header value: " + allow )
292
313
}
293
314
if custom {
@@ -318,7 +339,7 @@ func TestRouterNotAllowed(t *testing.T) {
318
339
router .ServeHTTP (w , r )
319
340
if ! (w .Code == http .StatusMethodNotAllowed ) {
320
341
t .Errorf ("NotAllowed handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
321
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, OPTIONS " {
342
+ } else if allow := w .Header ().Get ("Allow" ); allow != "OPTIONS, POST " {
322
343
t .Error ("unexpected Allow header value: " + allow )
323
344
}
324
345
@@ -332,7 +353,7 @@ func TestRouterNotAllowed(t *testing.T) {
332
353
router .ServeHTTP (w , r )
333
354
if ! (w .Code == http .StatusMethodNotAllowed ) {
334
355
t .Errorf ("NotAllowed handling failed: Code=%d, Header=%v" , w .Code , w .Header ())
335
- } else if allow := w .Header ().Get ("Allow" ); allow != "POST, DELETE, OPTIONS" && allow != "DELETE , POST, OPTIONS " {
356
+ } else if allow := w .Header ().Get ("Allow" ); allow != "DELETE, OPTIONS, POST" {
336
357
t .Error ("unexpected Allow header value: " + allow )
337
358
}
338
359
@@ -350,7 +371,7 @@ func TestRouterNotAllowed(t *testing.T) {
350
371
if w .Code != http .StatusTeapot {
351
372
t .Errorf ("unexpected response code %d want %d" , w .Code , http .StatusTeapot )
352
373
}
353
- if allow := w .Header ().Get ("Allow" ); allow != "POST, DELETE, OPTIONS" && allow != "DELETE , POST, OPTIONS " {
374
+ if allow := w .Header ().Get ("Allow" ); allow != "DELETE, OPTIONS, POST" {
354
375
t .Error ("unexpected Allow header value: " + allow )
355
376
}
356
377
}
0 commit comments