Skip to content

Commit

Permalink
fix: return text when content type is text/* (#579)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Bankhead <dan@danielbankhead.com>
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 30, 2024
1 parent 207b509 commit 3cc1c76
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
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
Expand Up @@ -669,6 +669,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 3cc1c76

Please sign in to comment.