Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Forward endpoint errors to httpsRequest #185

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,12 @@ function OutgoingResponse(stream) {
this.stream = stream;
this.statusCode = 200;
this.sendDate = true;

var self = this;
this.stream.on('error', function (error) {
self._log.error('Stream error: ' + error.toString());
self.emit('error', error);
});
this.stream.on('error', this.emit.bind(this, 'error'));
this.stream.once('headers', this._onRequestHeaders.bind(this));
}
OutgoingResponse.prototype = Object.create(OutgoingMessage.prototype, { constructor: { value: OutgoingResponse } });
Expand Down Expand Up @@ -970,6 +975,10 @@ Agent.prototype.request = function request(options, callback) {
endpoint = new Endpoint(self._log, 'CLIENT', self._settings);
endpoint.socket = httpsRequest.socket;
endpoint.pipe(endpoint.socket).pipe(endpoint);
endpoint.on('error', function (error) {
self._log.error('Endpoint error: ' + error.toString());
httpsRequest.emit('error', error);
});
}
if (started) {
// ** In the meantime, an other connection was made to the same host...
Expand Down Expand Up @@ -1059,6 +1068,12 @@ OutgoingRequest.prototype._start = function _start(stream, options) {
this.options = options;

this._log = stream._log.child({ component: 'http' });

var self = this;
stream.on('error', function (error) {
self._log.error('Stream error: ' + error.toString());
self.emit('error', error);
});

for (var key in options.headers) {
this.setHeader(key, options.headers[key]);
Expand Down
4 changes: 2 additions & 2 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ describe('http.js', function() {
} else {
called = true;
}
}, once: util.noop };
}, once: util.noop, on: util.noop };
var response = new http2.OutgoingResponse(stream);

response.writeHead(200);
response.writeHead(404);
});
it('field finished should be Boolean', function(){
var stream = { _log: util.log, headers: function () {}, once: util.noop };
var stream = { _log: util.log, headers: function () {}, once: util.noop, on: util.noop };
var response = new http2.OutgoingResponse(stream);
expect(response.finished).to.be.a('Boolean');
});
Expand Down