Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Push the EOF signaling null chunk after replaying proxy errors #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
// replay the "buffers" Buffer onto the `socket`, since at this point
// the HTTP module machinery has been hooked up for the user
socket.push(buffers);
socket.push(null);

// nullify the cached Buffer instance
buffers = null;
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ describe('HttpsProxyAgent', function() {

req.on('abort', done);
});
it('should emit an "end" event on the `http.IncomingMessage` if the proxy responds with non-200 status code', function(done) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like like to shorten this title but I can't think of a more concise way to say the same thing.

proxy.authenticate = function(req, fn) {
fn(null, false);
};

const proxyUri =
process.env.HTTP_PROXY ||
process.env.http_proxy ||
'http://localhost:' + proxyPort;

const req = http.get(
{
agent: new HttpsProxyAgent(proxyUri)
},
function(res) {
assert.equal(407, res.statusCode);

res.resume();
res.on('end', done);
}
);
});
it('should emit an "error" event on the `http.ClientRequest` if the proxy does not exist', function(done) {
// port 4 is a reserved, but "unassigned" port
var proxyUri = 'http://localhost:4';
Expand Down