@@ -657,6 +657,73 @@ describe('compression()', function () {
657657 . end ( )
658658 } )
659659 } )
660+
661+ describe ( 'defaultEncoding' , function ( ) {
662+ it ( 'should compress the provided encoding and not the default encoding' , function ( done ) {
663+ var server = createServer ( { threshold : 0 , defaultEncoding : 'deflate' } , function ( req , res ) {
664+ res . setHeader ( 'Content-Type' , 'text/plain' )
665+ res . end ( 'hello, world' )
666+ } )
667+
668+ request ( server )
669+ . get ( '/' )
670+ . set ( 'Accept-Encoding' , 'gzip' )
671+ . expect ( 'Content-Encoding' , 'gzip' )
672+ . expect ( 200 , 'hello, world' , done )
673+ } )
674+
675+ it ( 'should not compress when defaultEncoding is identity' , function ( done ) {
676+ var server = createServer ( { threshold : 0 , defaultEncoding : 'identity' } , function ( req , res ) {
677+ res . setHeader ( 'Content-Type' , 'text/plain' )
678+ res . end ( 'hello, world' )
679+ } )
680+
681+ request ( server )
682+ . get ( '/' )
683+ . set ( 'Accept-Encoding' , '' )
684+ . expect ( shouldNotHaveHeader ( 'Content-Encoding' ) )
685+ . expect ( 200 , 'hello, world' , done )
686+ } )
687+
688+ it ( 'should compress when defaultEncoding is gzip' , function ( done ) {
689+ var server = createServer ( { threshold : 0 , defaultEncoding : 'gzip' } , function ( req , res ) {
690+ res . setHeader ( 'Content-Type' , 'text/plain' )
691+ res . end ( 'hello, world' )
692+ } )
693+
694+ request ( server )
695+ . get ( '/' )
696+ . set ( 'Accept-Encoding' , '' )
697+ . expect ( 'Content-Encoding' , 'gzip' )
698+ . expect ( 200 , 'hello, world' , done )
699+ } )
700+
701+ it ( 'should compress when defaultEncoding is deflate' , function ( done ) {
702+ var server = createServer ( { threshold : 0 , defaultEncoding : 'deflate' } , function ( req , res ) {
703+ res . setHeader ( 'Content-Type' , 'text/plain' )
704+ res . end ( 'hello, world' )
705+ } )
706+
707+ request ( server )
708+ . get ( '/' )
709+ . set ( 'Accept-Encoding' , '' )
710+ . expect ( 'Content-Encoding' , 'deflate' )
711+ . expect ( 200 , 'hello, world' , done )
712+ } )
713+
714+ it ( 'should not compress when defaultEncoding is unknown' , function ( done ) {
715+ var server = createServer ( { threshold : 0 , defaultEncoding : 'bogus' } , function ( req , res ) {
716+ res . setHeader ( 'Content-Type' , 'text/plain' )
717+ res . end ( 'hello, world' )
718+ } )
719+
720+ request ( server )
721+ . get ( '/' )
722+ . set ( 'Accept-Encoding' , '' )
723+ . expect ( shouldNotHaveHeader ( 'Content-Encoding' ) )
724+ . expect ( 200 , 'hello, world' , done )
725+ } )
726+ } )
660727} )
661728
662729function createServer ( opts , fn ) {
0 commit comments