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

GZIP doesn't work with got #446

Closed
mikicho opened this issue Sep 24, 2023 · 3 comments · Fixed by #604
Closed

GZIP doesn't work with got #446

mikicho opened this issue Sep 24, 2023 · 3 comments · Fixed by #604

Comments

@mikicho
Copy link
Contributor

mikicho commented Sep 24, 2023

const { ClientRequestInterceptor } = require('@mswjs/interceptors/ClientRequest')
const got = require('got')
const zlib = require('zlib')

const interceptor = new ClientRequestInterceptor({
  name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('request', ({ request }) => {
  const compressed = zlib.gzipSync('hello')
  request.respondWith(new Response(compressed, {
    status: 200, headers: {
      'X-Transfer-Length': String(compressed.length),
      'Content-Length': undefined,
      'Content-Encoding': 'gzip',
    }
  }))
});

(async function () {
  console.log(1);
  console.log(await got('http://example.test/foo'))
  console.log(2);
})()

Specifically, got exits in this line with error code 0 (ok).
I couldn't catch the error (even with a try-catch), so I'm unsure what's happening.

It does work with native http.

May be related to: #308

@mikicho mikicho changed the title GZIP with got doesn't work GZIP doesn't work with got Sep 24, 2023
@mikicho
Copy link
Contributor Author

mikicho commented Sep 28, 2023

I investigated it further.
It seems like we don't emit a readable event. The for await (const chunk of stream) in got waits for a readable event, which is never emitted.
I suspect it is connected to the response clones, or maybe the ReadableStream in the createResponse

@kettanaito
Copy link
Member

This should be fixed by #604.

@kettanaito
Copy link
Member

Released: v0.36.6 🎉

This has been released in v0.36.6!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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 a pull request may close this issue.

2 participants