Skip to content

Commit

Permalink
fix: return text when content type is text/*
Browse files Browse the repository at this point in the history
  • Loading branch information
vinteo committed Oct 14, 2023
1 parent dd053c7 commit f49540c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/gaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,7 @@ export class Gaxios {
// continue
}
return data as {};
} else if (
contentType.includes('text/plain') ||
contentType.includes('text/html')
) {
} else if (contentType.match(/^text\//)) {
return response.text();
} else {
// If the content type is something not easily handled, just return the raw data (blob)
Expand Down
11 changes: 11 additions & 0 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,17 @@ describe('🎏 data handling', () => {
assert.deepStrictEqual(res.data, body);
});

it('should return text when response Content-Type=text/csv', async () => {
const body = '"col1","col2"\n"hello","world"';
const scope = nock(url)
.get('/')
.reply(200, body, {'Content-Type': 'text/csv'});
const res = await request({url});
scope.done();
assert.ok(res.data);
assert.deepStrictEqual(res.data, body);
});

it('should return raw data when Content-Type is unable to be parsed', async () => {
const body = Buffer.from('hello world', 'utf-8');
const scope = nock(url)
Expand Down

0 comments on commit f49540c

Please sign in to comment.