Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

ContentDecodingError while proxying requests to Github #8

Open
janbaer opened this issue Nov 30, 2017 · 2 comments
Open

ContentDecodingError while proxying requests to Github #8

janbaer opened this issue Nov 30, 2017 · 2 comments

Comments

@janbaer
Copy link

janbaer commented Nov 30, 2017

Hello, I'm trying to proxy requests to Github but I'm always getting this error on the serverside:

http: error: ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing: incorrect header check',))

Do you have any ideas how to solve it?

@marutypes
Copy link

marutypes commented May 2, 2018

I had this problem too! I just figured out the solution in my case.

In my case I had another middleware after the koa-better-http-proxy. The problem arises when your proxy middleware finishes. It's set the response to all of the right things, but then it calls next and whatever you have after it in the chain can clobber it.

My solution was to wrap it in my own middleware and pass () => Promise.resolve(null) to it as a second argument.

function myProxyWrapper(ctx) {
  await koaBetterHttpProxy(config)(shop, {
    ...myConfig,

    /*
      We want this middleware to terminate, not fall through to the next in the chain,
      but sadly it doesn't support not passing a `next` function. To get around this we
      just pass our own dummy `next` that resolves immediately.
    */
  })(ctx, () => Promise.resolve());
}

Another alternative might be to use the koa-mount middleware to stick it on it's own endpoint that won't interfere with anything (I think?)

  app.use(mount('/foo', koaBetterHttpProxy(config)))

I think this should at least be mentioned in the readme, and probably there should be a config option to skip calling next (maybe terminating: true).

@ajacksified
Copy link

ajacksified commented May 8, 2018

Just had this same issue; koa-mount only solves this particular issue if you don't have a catch-all middleware. In my case, I have a server-side-rendered react app and share react-router with the server and client, so I ended up having to wrap it all in a middleware anyways:

this.server.use(koaMount('/api', async ctx => {
  await koaProxy('api.somewebsite.com', {
    ...config
  })(ctx, () => Promise.resolve());
}));

Appreciate your comment getting me that far though, I was going a little crazy.

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

No branches or pull requests

3 participants