skewten-incubator / worse

websocket implementation
0 stars 0 forks source link

server custom validation architecture #6

Open SEAPUNK opened 8 years ago

SEAPUNK commented 8 years ago

so, i am halfway done with the server handshaking part of the server, but now i have a couple of things to think about and then implement:

first off, handshake acceptance. while i want validation to follow the RFC, i also want to allow people to change how those parts are handled.

currently, there is WSServer.handleUpgrade(), which is a call-and-forget function that handles connection upgrades. all listeners' upgrade handlers call this function, optionally providing themselves for some additional handling.

these are the things that are being checked/processed:

[cont.]

SEAPUNK commented 8 years ago

okay so first, i'll change the handleUpgrade function:

handleUpgrade(req, socket, upgradeHead, listener) to handleUpgrade(req, socket, upgradeHead, opts)

and create a private fn for listeners only:

_handleListenerUpgrade(req, socket, upgradeHead, listener)

SEAPUNK commented 8 years ago

and the handleUpgrade will be an options object with some defaults and will contain things like custom validators

SEAPUNK commented 8 years ago

this will change the flow like so:

SEAPUNK commented 8 years ago

_handleListenerUpgrade() will call handleUpgrade() with its own options object

SEAPUNK commented 8 years ago

this way,with custom functions, there is no need to worry about limitations or bikeshedding with things like middleware, because it can be layered on top of each other

SEAPUNK commented 8 years ago

good stuff