Skip to content

Commit

Permalink
fix: set responseType to buffer for http requests (#994)
Browse files Browse the repository at this point in the history
* Set `responseType` to buffer for HTTP requests

* docs(changelog): update

---------

Co-authored-by: Mattias Kindborg <[email protected]>
Co-authored-by: Mattias Kindborg <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2025
1 parent 5d7496e commit 16cbd4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/axis-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- [BREAKING CHANGE] Deprecate Node.js v21 and below

### :syringe: Fixed

- [#994](https://github.com/FantasticFiasco/axis-js/pull/994) Fix issue with `get` function not returning the correct response type. (contribution by [@spinda](https://github.com/spinda))

### :policeman: Security

- Security vulnerability in transient dependency `http-cache-semantics`
Expand Down
3 changes: 2 additions & 1 deletion packages/axis-core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { Response } from './Response';
*/
export const get = (connection: Connection, relativePath: string): Promise<Response> => {
const url = connection.url + format(relativePath);
return clientProvider('GET', url, connection.username, connection.password, connection?.options?.agent).get<Buffer>(url);
const client = clientProvider('GET', url, connection.username, connection.password, connection?.options?.agent);
return client.get(url, { responseType: 'buffer' });
};

const format = (relativePath: string): string => {
Expand Down
3 changes: 3 additions & 0 deletions packages/axis-core/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('#get should', () => {

// Assert
expect(got.statusCode).toBe(200);
expect(got.body).toBeInstanceOf(Buffer);
expect(got.body.toString()).toBe('Success');
});

Expand All @@ -36,6 +37,7 @@ describe('#get should', () => {

// Assert
expect(got.statusCode).toBe(200);
expect(got.body).toBeInstanceOf(Buffer);
expect(got.body.toString()).toBe('Success');
});

Expand All @@ -48,6 +50,7 @@ describe('#get should', () => {

// Assert
expect(got.statusCode).toBe(200);
expect(got.body).toBeInstanceOf(Buffer);
expect(got.body.toString()).toBe('Success');
});

Expand Down

0 comments on commit 16cbd4f

Please sign in to comment.