anyproxy icon indicating copy to clipboard operation
anyproxy copied to clipboard

How to get binary data in the beforeSendResponse callback?

Open zachsa opened this issue 5 years ago • 0 comments

Hi. I'm looking for a way to access binary data from proxied resources upstream. Please let me know if this is possible!

Which platform are you running AnyProxy

Linux (Ubuntu 18)

The version of the AnyProxy

4.1.2

Your expected behavior of AnyProxy

I would like to be able to access binary data in the beforeSendResponse function. It seems like this is currently not possible

The actual behavior of AnyProxy

const beforeSendResponse = async (requestDetail, responseDetail) => {
  console.log(responseDetail.response)
}

This code logs the response, which is:

{
  statusCode: 304,
  header: {
    'Cache-Control': 'private, must-revalidate, max-age=0',
    Vary: 'Origin',
    Server: 'Microsoft-IIS/10.0,',
    'X-Content-Type-Options': 'nosniff',
    'X-XSS-Protection': '1; mode=block',
    'X-AspNet-Version': '4.0.30319',
    'X-Powered-By': 'ASP.NET',
    Date: 'Fri, 17 Apr 2020 06:10:21 GMT',
    Connection: 'close',
    'x-anyproxy-origin-content-length': 0
  },
  body: <Buffer >,
  rawBody: []
}

I know that in Node.js I would do something along the lines of:

result = ''
res.on('data', (body) => result += body)
res.on('end', ...)

I understand that this is handling 'chunks' sent as a response by the upstream server? I'm not sure... I'm quite new to this.

But from what I can tell.... I simply just can't access the response body if that body is an image or other binary data.

Surely there is a way??

zachsa avatar Apr 17 '20 06:04 zachsa