@@ -2067,6 +2067,48 @@ test('async iterator yield object error', async (t) => {
20672067 await t . completed
20682068} )
20692069
2070+ test ( 'Successfully get a Response when neither a Transfer-Encoding or Content-Length header is present' , async ( t ) => {
2071+ t = tspl ( t , { plan : 4 } )
2072+ const server = createServer ( ( req , res ) => {
2073+ req . on ( 'data' , ( data ) => {
2074+ } )
2075+ req . on ( 'end' , ( ) => {
2076+ res . removeHeader ( 'transfer-encoding' )
2077+ res . writeHead ( 200 , {
2078+ // Header isn't actually necessary, but tells node to close after response
2079+ connection : 'close' ,
2080+ foo : 'bar'
2081+ } )
2082+ res . flushHeaders ( )
2083+ res . end ( 'a response body' )
2084+ } )
2085+ } )
2086+ after ( ( ) => server . close ( ) )
2087+
2088+ server . listen ( 0 , ( ) => {
2089+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
2090+ after ( ( ) => client . close ( ) )
2091+
2092+ client . request ( { path : '/' , method : 'GET' } , ( err , { body, headers } ) => {
2093+ t . ifError ( err )
2094+ t . equal ( headers [ 'content-length' ] , undefined )
2095+ t . equal ( headers [ 'transfer-encoding' ] , undefined )
2096+ const bufs = [ ]
2097+ body . on ( 'error' , ( ) => {
2098+ t . fail ( 'Closing the connection is valid' )
2099+ } )
2100+ body . on ( 'data' , ( buf ) => {
2101+ bufs . push ( buf )
2102+ } )
2103+ body . on ( 'end' , ( ) => {
2104+ t . equal ( 'a response body' , Buffer . concat ( bufs ) . toString ( 'utf8' ) )
2105+ } )
2106+ } )
2107+ } )
2108+
2109+ await t . completed
2110+ } )
2111+
20702112function buildParams ( path ) {
20712113 const cleanPath = path . replace ( '/?' , '' ) . replace ( '/' , '' ) . split ( '&' )
20722114 const builtParams = cleanPath . reduce ( ( acc , entry ) => {
0 commit comments