Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

handleUpgrade wasn't compatible with WS spec #12

Closed
wants to merge 3 commits into from
Closed

handleUpgrade wasn't compatible with WS spec #12

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 30, 2018

handleUpgrade wasn't compatible with WS module spec

handleUpgrade wasn't compatible with WS module spec
Copy link
Member

@goriunov goriunov left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request there are few things you need to change/clarify :). I can not see entry for upgradeHead and callback as handleUpgrade is a private function and you need to pass this data in from some where.

@@ -26,6 +26,8 @@ export class WebSocketServer extends eventEmitter() {
if (configs.path && configs.path[0] !== '/') {
configs.path = `/${configs.path}`;
}

this._upgradeCallback = noop;
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename variables to just upgradeCallback and move at the top with private tag (it is TypeScript not a JS so it has slightly different approach in creating variables) for reference check out upgradeListener variable.

@@ -151,7 +154,7 @@ export class WebSocketServer extends eventEmitter() {
return socket.end(`HTTP/1.1 ${code} ${name}\r\n\r\n`);
}

private handleUpgrade(req: HTTP.IncomingMessage, socket: Socket): void {
private handleUpgrade(req: HTTP.IncomingMessage, socket: Socket, upgradeHead, callback): void {
Copy link
Member

Choose a reason for hiding this comment

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

You need to specify types for upgradeHead and callback

@@ -165,6 +168,7 @@ export class WebSocketServer extends eventEmitter() {
if (!this.serverGroup) return;

this.upgradeReq = req;
this._upgradeCallback = callback ? callback : noop;
Copy link
Member

Choose a reason for hiding this comment

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

This is probably easier to write this._upgradeCallback = callback || noop;

@ghost
Copy link
Author

ghost commented Jan 3, 2019

@goriunov: is it allright now?

Copy link
Member

@goriunov goriunov left a comment

Choose a reason for hiding this comment

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

handleUpgrade does not really works the same way as WS library has even after this changes as it is not exposed if we are adding this logic we will need to also add upgrade event and hook up handleUpgrade together. Plus rewrite handleUpgrade logic abit.

lib/cws/server.ts Show resolved Hide resolved
@goriunov goriunov closed this Jun 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant