node.js - Why can't I remove the transfer-encoding header in a node proxy? -


I have a node http-proxy server that rewrites the body with some response which basically does this Send the node proxy localhost: 8000 -> example.com/api

  • The server json
    1. Client GET Localhost: 8000 / API / Items
    2. Code> [{id: 1234, url: http://example.com/api/items/1234}]
    3. The node proxy is changed to json by [ {Id: 1234, url: http: // local host: 8000 / API / item / 1234}] node proxy Calculates the new content-length header, sets it up, and responds to the client

    Backend server was working fine to enable compression . So now, by default, responses were being gipped, by default, the responses were being gipped. I worked around it by setting it in my proxy:

    req.headers ['accept-encoding'] = 'deflate'; After that, the answer was not being gyped, I could parse them and rewrite the body as necessary first. However, it stopped working with IE. I think the problem is that the response is still a transfer-encoding = chunked header, so IE expects a cold response. Because this transfer-encoding header exists, there is no content-length header, even if I'm setting it explicitly (those two headers are mutually exclusive ). I've tried everything that I can think about by removing the transfer encoding header and instead get the content-length header, but nothing works not doing. I have tried all of these:

    // In reference to my middleware response Write head function res.setHeader ('Transfer encoding', blank); Res.setHeader ('transfer-encoding', ''); Res.removeHeader ('transfer encoding'); Res.setHeader ('content-length', modified buffer lamps); // This line works alone before res.originalWriteHead.call (res, statusCode, {'content-length', modified buffer.lumb}}; // in reference to my middleware response. Written function res.write (data) , Encoding) // Here, the encoding parameter is unspecified // According to docs, encoding default for UFT 8 can be recorded 'Resold.write.call (res, modified buffer,' utf8 '); Res.oldWrite Res .old (res, modified buffer, empty); // res.end

    All three tried the same last, in fact, whatever I do, the feedback is not stolen, but transfer- encoding header set, and content-length not Firefox Safari, Chrome all seem to handle it properly, but the IEE error XMLHttpRequest: Network error 0x800c0007 fails, there is no data available for the requested resource. . This is (which I can tell I am) because this chunks ( Transfer-encoding header), but the response ends, and there is no content-length to read.

    Do anyone know how I can solve it? What is doing something wrong in trying to remove transfer-encoding header in content-length

    I have removed it myself:

    I have effectively used two middleware components (my own, described in question) and express.js compression Was using. My middleware was uncompressing the response, but compression ensures that the reaction is always written with the transfer-encoding = chosen and content-length .

    Removed the Express.js Compression module and solved it for me.


    Comments

    1. Thank you for sharing wonderful information with us to get some idea about that content.
      Thank a lot for this post that was very interesting. Keep posting like those amazing posts, this is really awesome :)
      oracle training in chennai

      oracle training institute in chennai

      oracle training in bangalore

      oracle training in hyderabad

      oracle training

      oracle online training

      hadoop training in chennai

      hadoop training in bangalore

      ReplyDelete

    Post a Comment