Skip to content

Commit

Permalink
fix(fetch): fix headers getting from a stream response; (#6401)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed May 18, 2024
1 parent 95a3e8e commit 870e0a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adapters/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default isFetchSupported && (async (config) => {
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
const options = {};

Object.getOwnPropertyNames(response).forEach(prop => {
['status', 'statusText', 'headers'].forEach(prop => {
options[prop] = response[prop];
});

Expand Down
13 changes: 13 additions & 0 deletions test/unit/adapters/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,17 @@ describe('supports fetch with nodejs', function () {
assert.strictEqual(err.cause && err.cause.code, 'ENOTFOUND');
}
});

it('should get response headers', async () => {
server = await startHTTPServer((req, res) => {
res.setHeader('foo', 'bar');
res.end(req.url)
});

const {headers} = await fetchAxios.get('/', {
responseType: 'stream'
});

assert.strictEqual(headers.get('foo'), 'bar');
});
});

0 comments on commit 870e0a7

Please sign in to comment.