@@ -126,7 +126,10 @@ const {
126
126
HTTP_STATUS_OK ,
127
127
HTTP_STATUS_NO_CONTENT ,
128
128
HTTP_STATUS_NOT_MODIFIED ,
129
- HTTP_STATUS_SWITCHING_PROTOCOLS
129
+ HTTP_STATUS_SWITCHING_PROTOCOLS ,
130
+
131
+ STREAM_OPTION_EMPTY_PAYLOAD ,
132
+ STREAM_OPTION_GET_TRAILERS
130
133
} = constants ;
131
134
132
135
// Top level to avoid creating a closure
@@ -411,20 +414,22 @@ function requestOnConnect(headers, options) {
411
414
return ;
412
415
}
413
416
414
- let getTrailers = false ;
417
+ let streamOptions = 0 ;
418
+ if ( options . endStream )
419
+ streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD ;
420
+
415
421
if ( typeof options . getTrailers === 'function' ) {
416
- getTrailers = true ;
422
+ streamOptions |= STREAM_OPTION_GET_TRAILERS ;
417
423
this [ kState ] . getTrailers = options . getTrailers ;
418
424
}
419
425
420
426
// ret will be either the reserved stream ID (if positive)
421
427
// or an error code (if negative)
422
428
const ret = handle . submitRequest ( headersList ,
423
- ! ! options . endStream ,
429
+ streamOptions ,
424
430
options . parent | 0 ,
425
431
options . weight | 0 ,
426
- ! ! options . exclusive ,
427
- getTrailers ) ;
432
+ ! ! options . exclusive ) ;
428
433
429
434
// In an error condition, one of three possible response codes will be
430
435
// possible:
@@ -1567,7 +1572,7 @@ function processHeaders(headers) {
1567
1572
}
1568
1573
1569
1574
function processRespondWithFD ( fd , headers , offset = 0 , length = - 1 ,
1570
- getTrailers = false ) {
1575
+ streamOptions = 0 ) {
1571
1576
const session = this [ kSession ] ;
1572
1577
const state = this [ kState ] ;
1573
1578
state . headersSent = true ;
@@ -1577,7 +1582,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1,
1577
1582
1578
1583
const handle = session [ kHandle ] ;
1579
1584
const ret =
1580
- handle . submitFile ( this [ kID ] , fd , headers , offset , length , getTrailers ) ;
1585
+ handle . submitFile ( this [ kID ] , fd , headers , offset , length , streamOptions ) ;
1581
1586
let err ;
1582
1587
switch ( ret ) {
1583
1588
case NGHTTP2_ERR_NOMEM :
@@ -1592,7 +1597,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1,
1592
1597
}
1593
1598
}
1594
1599
1595
- function doSendFD ( session , options , fd , headers , getTrailers , err , stat ) {
1600
+ function doSendFD ( session , options , fd , headers , streamOptions , err , stat ) {
1596
1601
if ( this . destroyed || session . destroyed ) {
1597
1602
abort ( this ) ;
1598
1603
return ;
@@ -1622,10 +1627,10 @@ function doSendFD(session, options, fd, headers, getTrailers, err, stat) {
1622
1627
processRespondWithFD . call ( this , fd , headersList ,
1623
1628
statOptions . offset ,
1624
1629
statOptions . length ,
1625
- getTrailers ) ;
1630
+ streamOptions ) ;
1626
1631
}
1627
1632
1628
- function doSendFileFD ( session , options , fd , headers , getTrailers , err , stat ) {
1633
+ function doSendFileFD ( session , options , fd , headers , streamOptions , err , stat ) {
1629
1634
if ( this . destroyed || session . destroyed ) {
1630
1635
abort ( this ) ;
1631
1636
return ;
@@ -1680,10 +1685,10 @@ function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) {
1680
1685
processRespondWithFD . call ( this , fd , headersList ,
1681
1686
options . offset ,
1682
1687
options . length ,
1683
- getTrailers ) ;
1688
+ streamOptions ) ;
1684
1689
}
1685
1690
1686
- function afterOpen ( session , options , headers , getTrailers , err , fd ) {
1691
+ function afterOpen ( session , options , headers , streamOptions , err , fd ) {
1687
1692
const state = this [ kState ] ;
1688
1693
const onError = options . onError ;
1689
1694
if ( this . destroyed || session . destroyed ) {
@@ -1701,7 +1706,8 @@ function afterOpen(session, options, headers, getTrailers, err, fd) {
1701
1706
state . fd = fd ;
1702
1707
1703
1708
fs . fstat ( fd ,
1704
- doSendFileFD . bind ( this , session , options , fd , headers , getTrailers ) ) ;
1709
+ doSendFileFD . bind ( this , session , options , fd ,
1710
+ headers , streamOptions ) ) ;
1705
1711
}
1706
1712
1707
1713
function streamOnError ( err ) {
@@ -1785,9 +1791,9 @@ class ServerHttp2Stream extends Http2Stream {
1785
1791
throw headersList ;
1786
1792
}
1787
1793
1788
- const ret = handle . submitPushPromise ( this [ kID ] ,
1789
- headersList ,
1790
- options . endStream ) ;
1794
+ const streamOptions = options . endStream ? STREAM_OPTION_EMPTY_PAYLOAD : 0 ;
1795
+
1796
+ const ret = handle . submitPushPromise ( this [ kID ] , headersList , streamOptions ) ;
1791
1797
let err ;
1792
1798
switch ( ret ) {
1793
1799
case NGHTTP2_ERR_NOMEM :
@@ -1843,14 +1849,17 @@ class ServerHttp2Stream extends Http2Stream {
1843
1849
options = Object . assign ( Object . create ( null ) , options ) ;
1844
1850
options . endStream = ! ! options . endStream ;
1845
1851
1846
- let getTrailers = false ;
1852
+ let streamOptions = 0 ;
1853
+ if ( options . endStream )
1854
+ streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD ;
1855
+
1847
1856
if ( options . getTrailers !== undefined ) {
1848
1857
if ( typeof options . getTrailers !== 'function' ) {
1849
1858
throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' ,
1850
1859
'getTrailers' ,
1851
1860
options . getTrailers ) ;
1852
1861
}
1853
- getTrailers = true ;
1862
+ streamOptions |= STREAM_OPTION_GET_TRAILERS ;
1854
1863
state . getTrailers = options . getTrailers ;
1855
1864
}
1856
1865
@@ -1880,10 +1889,7 @@ class ServerHttp2Stream extends Http2Stream {
1880
1889
1881
1890
const handle = session [ kHandle ] ;
1882
1891
const ret =
1883
- handle . submitResponse ( this [ kID ] ,
1884
- headersList ,
1885
- options . endStream ,
1886
- getTrailers ) ;
1892
+ handle . submitResponse ( this [ kID ] , headersList , streamOptions ) ;
1887
1893
let err ;
1888
1894
switch ( ret ) {
1889
1895
case NGHTTP2_ERR_NOMEM :
@@ -1936,14 +1942,14 @@ class ServerHttp2Stream extends Http2Stream {
1936
1942
options . statCheck ) ;
1937
1943
}
1938
1944
1939
- let getTrailers = false ;
1945
+ let streamOptions = 0 ;
1940
1946
if ( options . getTrailers !== undefined ) {
1941
1947
if ( typeof options . getTrailers !== 'function' ) {
1942
1948
throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' ,
1943
1949
'getTrailers' ,
1944
1950
options . getTrailers ) ;
1945
1951
}
1946
- getTrailers = true ;
1952
+ streamOptions |= STREAM_OPTION_GET_TRAILERS ;
1947
1953
state . getTrailers = options . getTrailers ;
1948
1954
}
1949
1955
@@ -1962,7 +1968,8 @@ class ServerHttp2Stream extends Http2Stream {
1962
1968
1963
1969
if ( options . statCheck !== undefined ) {
1964
1970
fs . fstat ( fd ,
1965
- doSendFD . bind ( this , session , options , fd , headers , getTrailers ) ) ;
1971
+ doSendFD . bind ( this , session , options , fd ,
1972
+ headers , streamOptions ) ) ;
1966
1973
return ;
1967
1974
}
1968
1975
@@ -1976,7 +1983,7 @@ class ServerHttp2Stream extends Http2Stream {
1976
1983
processRespondWithFD . call ( this , fd , headersList ,
1977
1984
options . offset ,
1978
1985
options . length ,
1979
- getTrailers ) ;
1986
+ streamOptions ) ;
1980
1987
}
1981
1988
1982
1989
// Initiate a file response on this Http2Stream. The path is passed to
@@ -2018,14 +2025,14 @@ class ServerHttp2Stream extends Http2Stream {
2018
2025
options . statCheck ) ;
2019
2026
}
2020
2027
2021
- let getTrailers = false ;
2028
+ let streamOptions = 0 ;
2022
2029
if ( options . getTrailers !== undefined ) {
2023
2030
if ( typeof options . getTrailers !== 'function' ) {
2024
2031
throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE' ,
2025
2032
'getTrailers' ,
2026
2033
options . getTrailers ) ;
2027
2034
}
2028
- getTrailers = true ;
2035
+ streamOptions |= STREAM_OPTION_GET_TRAILERS ;
2029
2036
state . getTrailers = options . getTrailers ;
2030
2037
}
2031
2038
@@ -2039,7 +2046,7 @@ class ServerHttp2Stream extends Http2Stream {
2039
2046
}
2040
2047
2041
2048
fs . open ( path , 'r' ,
2042
- afterOpen . bind ( this , session , options , headers , getTrailers ) ) ;
2049
+ afterOpen . bind ( this , session , options , headers , streamOptions ) ) ;
2043
2050
}
2044
2051
2045
2052
// Sends a block of informational headers. In theory, the HTTP/2 spec
0 commit comments