My problem was not with the response (as I though originally), but rather the fact that the request module was encoding it's response body to unicode by default, when disabled (encoding: null
), the response body is converted to a buffer which is easily consumed by the response.
options = {
url: url,
encoding: null,
headers: {
'Authorization': auth
}
};
request(options,
function(e, r, b){
var encoding = (r.headers['content-type'].indexOf('image') === -1) ? 'utf8' : 'binary';
res.end(b, encoding);
});