Skip to content

Commit

Permalink
[https-proxy-agent] Slice the headers when parsing proxy server respo…
Browse files Browse the repository at this point in the history
…nse (#212)

Fixes #207.
  • Loading branch information
byjrack committed Jul 10, 2023
1 parent b75b5fd commit 23fe1e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-panthers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'https-proxy-agent': patch
---

Correct the header parsing logic to stop before the response content to avoid generating an exception.
2 changes: 1 addition & 1 deletion packages/https-proxy-agent/src/parse-proxy-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function parseProxyResponse(
return;
}

const headerParts = buffered.toString('ascii').split('\r\n');
const headerParts = buffered.slice(0,endOfHeaders).toString('ascii').split('\r\n');
const firstLine = headerParts.shift();
if (!firstLine) {
socket.destroy();
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,5 +462,5 @@ function requestAuthorization(
'Proxy-Authenticate': 'Basic realm="' + realm + '"',
};
res.writeHead(407, headers);
res.end();
res.end('Proxy authorization required');
}

1 comment on commit 23fe1e3

@vercel
Copy link

@vercel vercel bot commented on 23fe1e3 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

proxy-agents – ./

proxy-agents.vercel.app
proxy-agents-tootallnate.vercel.app
proxy-agents-git-main-tootallnate.vercel.app

Please sign in to comment.