Fix recording, generic and part of websocket.py.

WebSocketServer(...,  record='FILE_PREFIX')

The reocrd parameter will turn on recording of all messages sent
to and from the client. The record parameter is a file prefix. The
full file-name will be the prefix with an extension '.HANDLER_ID'
based on the handler ID.

Recording required some restructing of the encode and decode function
to return more information so that the recording functions can record
just the payload data and ignore the WebSockets framing/headers.

Caveats:
- Not all messages recorded as sent to the client were necessarily
  received by the client. For example, if several messages are queued
  for the client, but the connection is shutdown before the messages
  are actually sent, these queued messages will still appear in the
  recording.
- If the server is also handling HTTP requests then the handler ID
  extensions for the recorded files will be monotonic but not
  contiguous because only WebSocket connections are recorded, not HTTP
  requests.
This commit is contained in:
Joel Martin
2011-06-26 13:55:52 -05:00
parent d91d89167f
commit 7f487fdbd5
3 changed files with 113 additions and 81 deletions
+20 -4
View File
@@ -59,7 +59,9 @@ var api = {}, // Public API
'open' : function() {},
'close' : function() {},
'error' : function() {}
};
},
test_mode = false;
//
@@ -253,9 +255,13 @@ function init() {
function open(uri) {
init();
websocket = new WebSocket(uri, 'base64');
// TODO: future native binary support
//websocket = new WebSocket(uri, ['binary', 'base64']);
if (test_mode) {
websocket = {};
} else {
websocket = new WebSocket(uri, 'base64');
// TODO: future native binary support
//websocket = new WebSocket(uri, ['binary', 'base64']);
}
websocket.onmessage = recv_message;
websocket.onopen = function() {
@@ -289,6 +295,15 @@ function close() {
}
}
// Override internal functions for testing
// Takes a send function, returns reference to recv function
function testMode(override_send) {
test_mode = true;
api.send = override_send;
api.close = function () {};
return recv_message;
}
function constructor() {
// Configuration settings
api.maxBufferedAmount = 200;
@@ -319,6 +334,7 @@ function constructor() {
api.init = init;
api.open = open;
api.close = close;
api.testMode = testMode;
return api;
}