@@ -657,6 +657,60 @@ describe('compression()', function () {
657
657
. end ( )
658
658
} )
659
659
} )
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 ( 'Content-Encoding' , 'identity' )
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
+ } )
660
714
} )
661
715
662
716
function createServer ( opts , fn ) {
0 commit comments