File tree 2 files changed +25
-3
lines changed
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -426,13 +426,13 @@ Router.prototype.allowedMethods = function (options) {
426
426
throw notImplementedThrowable ;
427
427
} else {
428
428
ctx . status = 501 ;
429
- ctx . set ( 'Allow' , allowedArr ) ;
429
+ ctx . set ( 'Allow' , allowedArr . join ( ', ' ) ) ;
430
430
}
431
431
} else if ( allowedArr . length ) {
432
432
if ( ctx . method === 'OPTIONS' ) {
433
433
ctx . status = 200 ;
434
434
ctx . body = '' ;
435
- ctx . set ( 'Allow' , allowedArr ) ;
435
+ ctx . set ( 'Allow' , allowedArr . join ( ', ' ) ) ;
436
436
} else if ( ! allowed [ ctx . method ] ) {
437
437
if ( options . throw ) {
438
438
var notAllowedThrowable ;
@@ -444,7 +444,7 @@ Router.prototype.allowedMethods = function (options) {
444
444
throw notAllowedThrowable ;
445
445
} else {
446
446
ctx . status = 405 ;
447
- ctx . set ( 'Allow' , allowedArr ) ;
447
+ ctx . set ( 'Allow' , allowedArr . join ( ', ' ) ) ;
448
448
}
449
449
}
450
450
}
Original file line number Diff line number Diff line change @@ -754,6 +754,28 @@ describe('Router', function () {
754
754
done ( ) ;
755
755
} ) ;
756
756
} ) ;
757
+
758
+ it ( 'sets the allowed methods to a single Allow header #273' , function ( done ) {
759
+ // https://tools.ietf.org/html/rfc7231#section-7.4.1
760
+ var app = new Koa ( ) ;
761
+ var router = new Router ( ) ;
762
+ app . use ( router . routes ( ) ) ;
763
+ app . use ( router . allowedMethods ( ) ) ;
764
+
765
+ router . get ( '/' , function ( ctx , next ) { } ) ;
766
+
767
+ request ( http . createServer ( app . callback ( ) ) )
768
+ . options ( '/' )
769
+ . expect ( 200 )
770
+ . end ( function ( err , res ) {
771
+ if ( err ) return done ( err ) ;
772
+ res . header . should . have . property ( 'allow' , 'HEAD, GET' ) ;
773
+ let allowHeaders = res . res . rawHeaders . filter ( ( item ) => item == 'Allow' ) ;
774
+ expect ( allowHeaders . length ) . to . eql ( 1 ) ;
775
+ done ( ) ;
776
+ } ) ;
777
+ } ) ;
778
+
757
779
} ) ;
758
780
759
781
it ( 'supports custom routing detect path: ctx.routerPath' , function ( done ) {
You can’t perform that action at this time.
0 commit comments