node-http-proxy-json icon indicating copy to clipboard operation
node-http-proxy-json copied to clipboard

Response break if write more "text" / "attributes" to the body

Open iroy2000 opened this issue 10 years ago • 3 comments

Thanks for creating this package.

We have problem that the json response got cut off when you put in more than one attributes. ( might be because of content length ) ?

It is working when you add one value, but seems like it is broken when you add more than one value

If one value as in example

    modifyResponse(res, proxyRes.headers['content-encoding'], function (body) {
        if (body) {
            // modify some information
            body.version = 2;
        }
        return body;
    });

Result --> It return as an full JSON screen shot 2016-08-08 at 6 20 15 pm


If more than one value

    modifyResponse(res, proxyRes.headers['content-encoding'], function (body) {
      if (body) {
        // modify some information
        // just adding one more attribute here below
        body.version = 2;
        body.age = 2;
      }
      return body;
    });

Result --> It actually cut off, NOT a valid JSON screen shot 2016-08-08 at 6 18 50 pm

iroy2000 avatar Aug 09 '16 01:08 iroy2000

Ok, just answering my question, delete the content length will work ...

    delete proxyRes.headers['content-length'];

iroy2000 avatar Aug 09 '16 01:08 iroy2000

Well it works but deleting the Content-Length header will switch the response to Transfer-Encoding: chunked mode.

It's useful for dynamic content (streaming something for example) but a solution with the Content-Length header would be better.

gogson avatar Jul 11 '17 14:07 gogson

the same issue here - after modifying the response it fails... content-length header is not changing when the response is changed - this is the problem... could you please fix it or tell how to overcome the issue?

art1c0 avatar Jul 19 '17 16:07 art1c0