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

Set responseType to buffer for HTTP requests #994

Merged
merged 5 commits into from
Jan 14, 2025

Conversation

spinda
Copy link
Contributor

@spinda spinda commented Dec 22, 2024

Description

Currently, making requests to the camera's HTTP API works like this:

return clientProvider('GET', url, connection.username, connection.password, connection?.options?.agent).get<Buffer>(url);

Unfortunately, passing Buffer to get as a type parameter only sets the response's data type to Buffer at the type level. It doesn't change the behavior of get at runtime, which actually still returns a string because the responseType option defaults to 'text'. This happens to kinda work anyway because .toString() and .length are available and work the same on both string and Buffer values, but taking a snapshot returns corrupted data, because got tries to decode the binary JPEG/BMP data as UTF-8 text. Setting responseType to 'buffer' corrects this.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (N/A)
  • I have added tests that prove my fix is effective or that my feature works

@FantasticFiasco
Copy link
Owner

Thanks for the PR! I'll look it over during the holidays.

@FantasticFiasco
Copy link
Owner

@spinda can you please give me write permissions to the branch on your fork?

@spinda
Copy link
Contributor Author

spinda commented Jan 3, 2025

Oh, why do you need write permissions on our repo?

@FantasticFiasco
Copy link
Owner

Would like to add a commit on the PR before we merge it. The option to give me write access to your branch on your fork was an option when you created the PR.

@FantasticFiasco FantasticFiasco merged commit 16cbd4f into FantasticFiasco:main Jan 14, 2025
@FantasticFiasco
Copy link
Owner

Thanks for your contribution @spinda!

@FantasticFiasco
Copy link
Owner

A new version of the library has been published for you at https://www.npmjs.com/package/axis-core/v/2.0.0. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants