@@ -371,15 +371,8 @@ describe('transmission', () => {
371
371
expect ( res . headers [ 'content-encoding' ] ) . to . equal ( 'gzip' ) ;
372
372
expect ( res . headers . vary ) . to . equal ( 'accept-encoding' ) ;
373
373
374
- await new Promise ( ( resolve ) => {
375
-
376
- Zlib . unzip ( res . rawPayload , ( err , result ) => {
377
-
378
- expect ( err ) . to . not . exist ( ) ;
379
- expect ( result . toString ( ) ) . to . equal ( '/**/docall({"first":"1","last":"2"});' ) ;
380
- resolve ( ) ;
381
- } ) ;
382
- } ) ;
374
+ const uncompressed = await internals . uncompress ( 'unzip' , res . rawPayload ) ;
375
+ expect ( uncompressed . toString ( ) ) . to . equal ( '/**/docall({"first":"1","last":"2"});' ) ;
383
376
} ) ;
384
377
385
378
it ( 'returns an JSONP response when response is a buffer' , async ( ) => {
@@ -1772,6 +1765,49 @@ describe('transmission', () => {
1772
1765
} ) ;
1773
1766
} ) ;
1774
1767
1768
+ describe ( 'encoding()' , ( ) => {
1769
+
1770
+ it ( 'passes compressor to stream' , async ( ) => {
1771
+
1772
+ const handler = ( request , h ) => {
1773
+
1774
+ const TestStream = class extends Stream . Readable {
1775
+
1776
+ _read ( size ) {
1777
+
1778
+ if ( this . isDone ) {
1779
+ return ;
1780
+ }
1781
+ this . isDone = true ;
1782
+
1783
+ this . push ( 'some payload' ) ;
1784
+ this . _compressor . flush ( ) ;
1785
+
1786
+ setTimeout ( ( ) => {
1787
+
1788
+ this . push ( ' and some other payload' ) ;
1789
+ this . push ( null ) ;
1790
+ } , 10 ) ;
1791
+ }
1792
+
1793
+ setCompressor ( compressor ) {
1794
+
1795
+ this . _compressor = compressor ;
1796
+ }
1797
+ } ;
1798
+
1799
+ return h . response ( new TestStream ( ) ) . type ( 'text/html' ) ;
1800
+ } ;
1801
+
1802
+ const server = Hapi . server ( { compression : { minBytes : 1 } } ) ;
1803
+ server . route ( { method : 'GET' , path : '/' , handler } ) ;
1804
+
1805
+ const res = await server . inject ( { url : '/' , headers : { 'accept-encoding' : 'gzip' } } ) ;
1806
+ const uncompressed = await internals . uncompress ( 'unzip' , res . rawPayload ) ;
1807
+ expect ( uncompressed . toString ( ) ) . to . equal ( 'some payload and some other payload' ) ;
1808
+ } ) ;
1809
+ } ) ;
1810
+
1775
1811
describe ( 'writeHead()' , ( ) => {
1776
1812
1777
1813
it ( 'set custom statusMessage' , async ( ) => {
@@ -1841,3 +1877,9 @@ internals.compress = function (encoder, value) {
1841
1877
1842
1878
return new Promise ( ( resolve ) => Zlib [ encoder ] ( value , ( ignoreErr , compressed ) => resolve ( compressed ) ) ) ;
1843
1879
} ;
1880
+
1881
+
1882
+ internals . uncompress = function ( decoder , value ) {
1883
+
1884
+ return new Promise ( ( resolve ) => Zlib [ decoder ] ( value , ( ignoreErr , uncompressed ) => resolve ( uncompressed ) ) ) ;
1885
+ } ;
0 commit comments