Don't delegate validFrameRsv() to extensions; it's a weird interface and we can figure it out from the extension metadata.

This commit is contained in:
James Coglan
2014-12-12 00:54:39 +00:00
parent 007cc0ac22
commit ea98426dc1
2 changed files with 13 additions and 31 deletions
+2 -25
View File
@@ -285,31 +285,8 @@ their use of RSV bits are not activated.
#### *Session*
The *Session* API must be implemented by both client and server sessions. It
contains three methods: `validFrameRsv(frame)`,
`processIncomingMessage(message)` and `processOutgoingMessage(message)`.
```js
session.validFrameRsv(frame)
```
This takes a *Frame* as defined above, and returns a response indicating which
RSV bits are allowed to be set on the frame. (If a session is having this method
called, the session is active and should its bits can be used.) For example, the
`permessage-deflate` extension allows the RSV1 bit to be set on `text` and
`binary` frames, and implements this method like this:
```js
Session.prototype.validFrameRsv = function(frame) {
if (frame.opcode === 1 || frame.opcode === 2) {
return {rsv1: true, rsv2: false, rsv3: false};
else
return {rsv1: false, rsv2: false, rsv3: false};
};
```
Note that returning `false` for an `rsvX` field does not mean the session is
forbidding its use; the framework assumes all RSV bits are banned unless a
session indicates otherwise.
contains two methods, `processIncomingMessage(message)` and
`processOutgoingMessage(message)`.
```js
session.processIncomingMessage(message, function(error, msg) { ... })
+11 -6
View File
@@ -12,6 +12,8 @@ var Extensions = function() {
this._index = {}
};
Extensions.MESSAGE_OPCODES = [1, 2];
var instance = {
add: function(ext) {
if (typeof ext.name !== 'string') throw new TypeError('extension.name must be a string');
@@ -111,14 +113,17 @@ var instance = {
validFrameRsv: function(frame) {
var allowed = {rsv1: false, rsv2: false, rsv3: false},
policy;
ext;
for (var i = 0, n = this._sessions.length; i < n; i++) {
policy = this._sessions[i][1].validFrameRsv(frame);
allowed.rsv1 = allowed.rsv1 || policy.rsv1;
allowed.rsv2 = allowed.rsv2 || policy.rsv2;
allowed.rsv3 = allowed.rsv3 || policy.rsv3;
if (Extensions.MESSAGE_OPCODES.indexOf(frame.opcode) >= 0) {
for (var i = 0, n = this._sessions.length; i < n; i++) {
ext = this._sessions[i][0];
allowed.rsv1 = allowed.rsv1 || ext.rsv1;
allowed.rsv2 = allowed.rsv2 || ext.rsv2;
allowed.rsv3 = allowed.rsv3 || ext.rsv3;
}
}
return (allowed.rsv1 || !frame.rsv1) &&
(allowed.rsv2 || !frame.rsv2) &&
(allowed.rsv3 || !frame.rsv3);