@@ -973,6 +973,93 @@ describe('compression()', function () {
973973 . expect ( 200 , done )
974974 } )
975975 } )
976+
977+ describe ( 'res.writeHead' , function ( ) {
978+ it ( 'should support headers with undefined statusMessage' , function ( done ) {
979+ var server = createServer ( { threshold : 0 } , function ( req , res ) {
980+ res . writeHead ( 200 , undefined , {
981+ 'Content-Type' : 'text/plain' ,
982+ 'X-Custom' : 'header'
983+ } )
984+ res . end ( 'hello, world' )
985+ } )
986+
987+ request ( server )
988+ . get ( '/' )
989+ . set ( 'Accept-Encoding' , 'gzip' )
990+ . expect ( 'X-Custom' , 'header' )
991+ . expect ( 'Content-Encoding' , 'gzip' )
992+ . expect ( 200 , 'hello, world' , done )
993+ } )
994+
995+ it ( 'should support headers with string statusMessage' , function ( done ) {
996+ var server = createServer ( { threshold : 0 } , function ( req , res ) {
997+ res . writeHead ( 200 , 'OK' , {
998+ 'Content-Type' : 'text/plain' ,
999+ 'X-Custom' : 'header'
1000+ } )
1001+ res . end ( 'hello, world' )
1002+ } )
1003+
1004+ request ( server )
1005+ . get ( '/' )
1006+ . set ( 'Accept-Encoding' , 'gzip' )
1007+ . expect ( 'X-Custom' , 'header' )
1008+ . expect ( 'Content-Encoding' , 'gzip' )
1009+ . expect ( 200 , 'hello, world' , done )
1010+ } )
1011+
1012+ it ( 'should support array headers with undefined statusMessage' , function ( done ) {
1013+ var server = createServer ( { threshold : 0 } , function ( req , res ) {
1014+ res . writeHead ( 200 , undefined , [
1015+ [ 'Content-Type' , 'text/plain' ] ,
1016+ [ 'X-Custom' , 'array' ]
1017+ ] )
1018+ res . end ( 'hello, world' )
1019+ } )
1020+
1021+ request ( server )
1022+ . get ( '/' )
1023+ . set ( 'Accept-Encoding' , 'gzip' )
1024+ . expect ( 'X-Custom' , 'array' )
1025+ . expect ( 'Content-Encoding' , 'gzip' )
1026+ . expect ( 200 , 'hello, world' , done )
1027+ } )
1028+
1029+ it ( 'should support array headers with string statusMessage' , function ( done ) {
1030+ var server = createServer ( { threshold : 0 } , function ( req , res ) {
1031+ res . writeHead ( 200 , 'OK' , [
1032+ [ 'Content-Type' , 'text/plain' ] ,
1033+ [ 'X-Custom' , 'array' ]
1034+ ] )
1035+ res . end ( 'hello, world' )
1036+ } )
1037+
1038+ request ( server )
1039+ . get ( '/' )
1040+ . set ( 'Accept-Encoding' , 'gzip' )
1041+ . expect ( 'X-Custom' , 'array' )
1042+ . expect ( 'Content-Encoding' , 'gzip' )
1043+ . expect ( 200 , 'hello, world' , done )
1044+ } )
1045+
1046+ it ( 'should support uncompressed response with undefined statusMessage' , function ( done ) {
1047+ var server = createServer ( { filter : function ( ) { return false } } , function ( req , res ) {
1048+ res . writeHead ( 200 , undefined , {
1049+ 'Content-Type' : 'text/plain' ,
1050+ 'X-Custom' : 'header'
1051+ } )
1052+ res . end ( 'hello, world' )
1053+ } )
1054+
1055+ request ( server )
1056+ . get ( '/' )
1057+ . set ( 'Accept-Encoding' , 'gzip' )
1058+ . expect ( 'X-Custom' , 'header' )
1059+ . expect ( shouldNotHaveHeader ( 'Content-Encoding' ) )
1060+ . expect ( 200 , 'hello, world' , done )
1061+ } )
1062+ } )
9761063} )
9771064
9781065function createServer ( opts , fn ) {
0 commit comments