question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not handling some binary responses correctly (with reproduction)

See original GitHub issue

Description

Requests fail when fetching binary data.

The binary data seems to be fetching and recording fine. But then it is somehow wrong, because when passing gzip’ed data to the zlib, it complains that the data is not valid.

So the data is either transformed or cut off in some way.

Shareable Source

See https://github.com/moltar/polly-octet-stream

Error Message & Stack Trace

incorrect header check

Config

Using @spotify/polly-jest-presets.

The config it ships with:

https://github.com/spotify/polly-jest-presets/blob/master/src/index.ts

Dependencies

From: https://github.com/spotify/polly-jest-presets/blob/master/package.json

Copy the @pollyjs dependencies from package.json:

  "dependencies": {
    "@pollyjs/adapter-node-http": "^2.6.0",
    "@pollyjs/core": "^2.6.0",
    "@pollyjs/persister-fs": "^2.6.0",
    "lodash.merge": "^4.6.2",
    "setup-polly-jest": "^0.5.2"
  }
  "devDependencies": {
    "@spotify/web-scripts": "^1.0.0",
    "@types/lodash.merge": "^4.6.6",
    "@types/pollyjs__adapter-node-http": "^2.0.0",
    "@types/pollyjs__core": "^2.3.0",
    "@types/pollyjs__persister-fs": "^2.0.0",
    "moment": "^2.24.0"
  }

Relevant Links

https://github.com/moltar/polly-octet-stream

Environment

Node.js v10.15.3
darwin 19.0.0
npm 6.13.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16

github_iconTop GitHub Comments

5reactions
offirgolancommented, Jan 8, 2020

Released with v3.0.2 🎉

1reaction
RubenVerborghcommented, Jan 7, 2020

Reproducible example:

// test.js
const fetch = require('node-fetch');
const { Polly } = require('@pollyjs/core');
const NodeHttpAdapter = require('@pollyjs/adapter-node-http');
const FsPersister = require('@pollyjs/persister-fs');

Polly.register(NodeHttpAdapter);
Polly.register(FsPersister);

describe('test', () => {
  let polly =  new Polly('test', {
    adapters: ['node-http'],
    persister: 'fs',
  });
  afterAll(() => polly.stop());

  it('test', async () => {
    const response = await fetch('http://perdu.com/');
    const text = await response.text();
    console.log(text);
  });
});
echo '{}' > package.json
npm i @pollyjs/adapter-node-http@3.0.0 @pollyjs/core@3.0.0 @pollyjs/persister-fs@3.0.0 jest@24.9.0 node-fetch@2.6.0
npx jest test.js

Results in:

FetchError: Invalid response body while trying to fetch http://perdu.com/: incorrect header check

The error disappears when uncommenting the Polly.js block.

This is the best MWE I could find; the bug disappears without jest or node-fetch for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not handling some binary responses correctly (with ... - GitHub
The binary data seems to be fetching and recording fine. ... Not handling some binary responses correctly (with reproduction) #278.
Read more >
Bacterial binary fission | The cell cycle and mitosis (article)
Binary fission has features in common with mitosis, but also differs from mitosis in some important ways. Let's take a look at how...
Read more >
24.1. Reproduction Methods – Concepts of Biology
Some unicellular eukaryotic organisms undergo binary fission by mitosis. In other organisms, part of the individual separates and forms a second individual.
Read more >
OHIO GRADUATION TESTS
The student response does not meet the criteria required to earn one ... Asexual reproduction (binary fission) leads to offspring that are genetically ......
Read more >
Science Test 1 Section 1 Flashcards - Quizlet
Asexual reproduction requires only one parent and produces non-identical offspring, while sexual reproduction requires two parents and produces identical ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found