Skip to content

Commit

Permalink
Use .end() to send body data in response.write() and writeHead()
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacgr committed Sep 11, 2021
1 parent be9624e commit 7a596b4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/server/protocol/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class HttpServerProtocol extends JsonRpcServerProtocol {
}

/**
* Send message to the client. If a notification is passed, then
* a 204 response code is sent.
* Send message to the client.
*
* @param {string} message Stringified JSON-RPC message object
*/
Expand All @@ -41,15 +40,12 @@ class HttpServerProtocol extends JsonRpcServerProtocol {
this.status = 200;
}
}
this.response.writeHead(this.status, this.headers);
this.response.write(message, () => {
this.response.end();
});
this.response.writeHead(this.status, this.headers).end(message);
}

/**
* Calls `emit` on factory with the event name being `message.method` and
* the date being `message`. Responds to client.
* the data being `message`.
*
* Responds to client with 204 status.
*
Expand All @@ -60,8 +56,7 @@ class HttpServerProtocol extends JsonRpcServerProtocol {
this.setResponseStatus({
notification: true
});
this.response.writeHead(this.status, this.headers);
this.response.end();
this.response.writeHead(this.status, this.headers).end();
}

/**
Expand All @@ -82,7 +77,6 @@ class HttpServerProtocol extends JsonRpcServerProtocol {
* @param {number} options.errorCode The JSON-RPC error code to lookup a corresponding status code for
* @param {number} options.status The HTTP status code (will override the errorCode)
* @param {boolean} options.notification Inidicate if setting header for notification (will override other options with 204 status)
*/
setResponseStatus({ errorCode, status, notification }) {
this.status = 200;
Expand Down

0 comments on commit 7a596b4

Please sign in to comment.