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

fix(adapter-node-http): Improve binary response body handling #329

Merged
merged 2 commits into from
Apr 30, 2020

Conversation

offirgolan
Copy link
Collaborator

Description

The core issue was in getChunksFromBody where we pass it the recorded body and response headers. Since the body is a string, it can't really know if the original buffer was binary or not. To get around that, we now store whether the response content is binary or not in the HAR file and expose it via the response class.

Motivation and Context

Resolves #327.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • My code follows the code style of this project.
  • My commits and the title of this PR follow the Conventional Commits Specification.
  • I have read the contributing guidelines.


server.get(url).passthrough(true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We weren't able to catch this issue since we were doing a passthrough which still went through the adapter.

@@ -37,6 +37,10 @@ export default class Response {

if (response.body && typeof response.body === 'string') {
this.content.text = response.body;

if (response.isBinary) {
this.content._isBinary = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

_isBinary is only going to the written to the har content if the content is binary. I didnt think it was necessary to always include it. @jasonmit thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

seems fair but some what on topic - does this constitute a breaking change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this is backwards compatible but does require to re-record to resolve the issue.

@offirgolan offirgolan merged commit 9466989 into master Apr 30, 2020
@offirgolan offirgolan deleted the node-http-handle-binary-data branch April 30, 2020 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working 📦 adapter-node-http
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The download file content is borken and the size looks doubled
2 participants