In short, I write my proxy server on node.js (it still comes in handy, but it’s just a proxy that has been used, I’ve been burning the topic for a long time, I wonder if it is still alive)
A proxy based on methods like .pipe () does not suit me - I need to pass complete data through myself, and so they will pass by. I need to download the data completely, process it and then send it.
Wrote a proxy on sockets based on examples - beats pictures (data of a different length than content-length is downloaded, and for smaller pictures the difference is smaller, for larger ones)
')
Rewrote on the http module - it still hits, the visibility of the problem is the same.
*** For a long time, nowhere, there is nothing about such a problem ...
The reason is that all the I / O with sockets and with http - has an indication of the encoding, and even if you do not specify it (optional parameter),
there is some default encoding inside, and it does something by default!That is, all the pictures of this encoding are processed somehow and spoil. And this is a separate question, what kind of crap is one encoding? Then there should be two - encoding before and after.
How to treat the problem with the encoding node.js
Put the encoding 'binary' - if you download, then before receiving the data you need to write something like
var req = http.request(options, function (res) { res.setEncoding('binary');
And when you send a picture, you need to add the second parameter, like
response.write(data,'binary');
And it will cease to climb into the data, and it also beats the html encoding, I just didn’t immediately notice, I saw it in the pictures first.
And nowhere, never on tips, examples of everybody on stackoverflow.com and documentation is there no, that this work with encoding is enabled by default and it spoils all data.
How is it at all? English, okay, don't care about the encoding, but the pictures? they calmly give such code examples that take the broken data and send ...
I'm not a pro programmer, inventing bicycles. Surely you will now find tons of open source proxies (satisfying the conditions above), you just had to
look at it ...