Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return text when content type is text/csv #579

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\//)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how specific the regular expression should be, hope this suits.

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 @@ -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
Loading