Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup: cleaner version
  • Loading branch information
ronag committed Jan 1, 2020
commit 2f0d4b109250179fa74f01a5df6f8a525cf1c23b
22 changes: 12 additions & 10 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,30 +651,32 @@ class Http2ServerResponse extends Stream {
}

write(chunk, encoding, cb) {
const state = this[kState];

if (typeof encoding === 'function') {
cb = encoding;
encoding = 'utf8';
}

if (this[kState].ending) {
const err = new ERR_STREAM_WRITE_AFTER_END();
if (typeof cb === 'function')
process.nextTick(cb, err);
this.destroy(err);
let err;
if (state.ending) {
err = new ERR_STREAM_WRITE_AFTER_END();
} else if (state.closed) {
err = new ERR_HTTP2_INVALID_STREAM();
} else if (state.destroyed) {
return false;
} else if (this[kState].closed) {
const err = new ERR_HTTP2_INVALID_STREAM();
}

if (err) {
if (typeof cb === 'function')
process.nextTick(cb, err);
this.destroy(err);
return false;
} else if (this[kState].destroyed) {
return false;
}

const stream = this[kStream];
if (!stream.headersSent)
this.writeHead(this[kState].statusCode);
this.writeHead(state.statusCode);
return stream.write(chunk, encoding, cb);
}

Expand Down