TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
919 stars 238 forks source link

Issue with header parse buffer logic #207

Closed byjrack closed 1 year ago

byjrack commented 1 year ago

So was getting some exceptions after the move from 5.0.1 to 6.1.0 and traced it to the new header parsing

I was noticing that headerParts seemed to collect all the content in the proxy response and not just the headers. In our case the 407 is accompanied by some HTML indicating the issue.

Looking at the code you grab endOfHeaders for building the buffer, but are not using it in the headerParts array creation. In my case that means the content page gets included and then you start getting Invalid Header exceptions.

I have not tested this heavily, especially on really long responses that might require the "end of" recursive call, but should headerParts only use a slice of buffered?

const headerParts = buffered.slice(0,endOfHeaders).toString('ascii').split('\r\n');
TooTallNate commented 1 year ago

Ya that seems like a bug. PR welcome!

byjrack commented 1 year ago

Cool I have a few internal gates to pass so may take a little bit even for a papercut, but hopefully shouldn't be stuck for long. I also want to run through your contributing to make sure I can tick all the boxes.