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

modifyGoogle.js from the examples fails with "Content Encoding Error" #257

Open
OnkelTem opened this issue May 1, 2022 · 10 comments
Open

Comments

@OnkelTem
Copy link

OnkelTem commented May 1, 2022

I'm using Firefox 99.0 (64-bit) on Linux Kubuntu 20.04

Running the example fails with this error:
image
when I open an URL like this one

Ideas?

@OnkelTem
Copy link
Author

OnkelTem commented May 1, 2022

I added console.log() in the onResponseData() handler:

 ctx.onResponseData(function (ctx, chunk, callback) {
      console.log(chunk.toString());
      ...

and it prints this:

Y͘��J�#���1�8�!�:
�&�[��>�h����ɩm3w����|�m�N���Jc`}<}�~�X�P�Q�@���`FpE�Xr���zLf��q�}��fߖ8~ջij�X4�*�� ����...

So maybe it's the Proxy.gunzip middleware that doesn't work properly?

@OnkelTem
Copy link
Author

OnkelTem commented May 1, 2022

I should say I installed only ca.pem certificate.
Not sure what else should I install.

@wawahuy
Copy link

wawahuy commented May 7, 2022

try https://www.npmjs.com/package/pms-proxy

@OnkelTem
Copy link
Author

OnkelTem commented May 8, 2022

Thanks @wawahuy
I switched to https://www.npmjs.com/package/mockttp

@vtulin
Copy link

vtulin commented May 15, 2022

Thanks @wawahuy I switched to https://www.npmjs.com/package/mockttp

Could you please give a short piece of code how to use it? I have the same issue

@OnkelTem
Copy link
Author

OnkelTem commented May 15, 2022

Could you please give a short piece of code how to use it? I have the same issue

Sure! I had the same question :)

httptoolkit/mockttp#76

And also, I've almost finished a standalone proxying script which is using mockttp. I'm gonna upload a fresh version in an hour or two.

@vtulin
Copy link

vtulin commented May 15, 2022

httptoolkit/mockttp#76

It looks like mockttp depends on a module called vm2 which has a binary, this is not equal replacement as http-mitm-proxy is script only. For me that's important as I'm using webvpack.

@vtulin
Copy link

vtulin commented May 15, 2022

So maybe it's the Proxy.gunzip middleware that doesn't work properly?

I found the problem, that was so simple, we should take a look on content-encoding in response, there we may see that Google not using gzip, it uses br (brotli). So the partial solution is:

import zlib from 'zlib';
...
ctx.addResponseFilter(zlib.createBrotliDecompress());

instead of:

ctx.use(Proxy.gunzip);

Check node_modules\http-mitm-proxy\lib\middleware\gunzip.js.
The best solution would be to check content-encoding and add required decompressor if needed.

@OnkelTem
Copy link
Author

Ok, I see you're solving a different task.
But since I promised to share, here is my proxy code: https://github.com/OnkelTem/wmod-proxy/blob/master/src/proxy.ts
(not finished or well tested)

@vtulin
Copy link

vtulin commented May 16, 2022

Ok, I see you're solving a different task. But since I promised to share, here is my proxy code: https://github.com/OnkelTem/wmod-proxy/blob/master/src/proxy.ts (not finished or well tested)

Thank you

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

No branches or pull requests

3 participants