8000 Handle zero-length OK deflate responses (#903) · node-fetch/node-fetch@838d971 · GitHub
[go: up one dir, main page]

Skip 10000 to content

Commit 838d971

Browse files
authored
Handle zero-length OK deflate responses (#903)
1 parent 1ef4b56 commit 838d971

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ export default function fetch(url, opts) {
275275
response = new Response(body, response_options);
276276
resolve(response);
277277
});
278+
raw.on('end', () => {
279+
// some old IIS servers return zero-length OK deflate responses, so 'data' is never emitted.
280+
if (!response) {
281+
response = new Response(body, response_options);
282+
resolve(response);
283+
}
284+
})
278285
return;
279286
}
280287

test/server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ export default class TestServer {
120120
});
121121
}
122122

123+
if (p === '/empty/deflate') {
124+
res.statusCode = 200;
125+
res.setHeader('Content-Type', 'text/plain');
126+
res.setHeader('Content-Encoding', 'deflate');
127+
res.end();
128+
}
129+
123130
if (p === '/sdch') {
124131
res.statusCode = 200;
125132
res.setHeader('Content-Type', 'text/plain');

test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,17 @@ describe('node-fetch', () => {
679679
});
680680
});
681681

682+
it('should handle empty deflate response', function() {
683+
const url = `${base}empty/deflate`;
684+
return fetch(url).then(res => {
685+
expect(res.headers.get('content-type')).to.equal('text/plain');
686+
return res.text().then(result => {
687+
expect(result).to.be.a('string');
688+
expect(result).to.be.empty;
689+
});
690+
});
691+
});
692+
682693
it('should decompress brotli response', function() {
683694
if(typeof zlib.createBrotliDecompress !== 'function') this.skip();
684695
const url = `${base}brotli`;

0 commit comments

Comments
 (0)
0