Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I did this a long time ago but I think it's all good changes #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion daemon/orbited2/js_src/Orbited2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jsio('import lib.Enum as Enum');

exports.logging = logging;
exports.logger = logger;
exports.settings = {};

exports.utf8 = utf8;

//logger.setLevel(0)

Expand Down Expand Up @@ -36,6 +39,22 @@ function setup() {
}
}

function getOrbitedUri() {
if (exports.settings.hostname) {
var output = 'http://'
if (exports.settings.protocol) {
output = exports.settings.protocol + '://'
}
output += exports.settings.hostname
if (exports.settings.port && exports.settings.port.toString() != '80') {
output += ':' + exports.settings.port;
}
return output;
}
return defaultOrbitedUri;
}


setup();

// TCPSocket code
Expand All @@ -51,7 +70,8 @@ var READY_STATE = Enum({
exports.TCPSocket = Class(function() {

this.init = function(opts) {
this._orbitedUri = opts.orbitedUri || defaultOrbitedUri;
opts = opts || {};
this._orbitedUri = opts.orbitedUri || getOrbitedUri();
if (!/\/$/.test(this._orbitedUri)) {
this._orbitedUri += '/';
}
Expand Down Expand Up @@ -282,6 +302,7 @@ function getMultiplexer(baseUri, forceTransport) {
}
// TODO: Choose transport
var _transport = forceTransport;
_transport = 'csp';
if (!_transport) {
if (!!originalWebSocket) { _transport = 'ws'; }
else { _transport = 'csp'; }
Expand Down
9 changes: 6 additions & 3 deletions daemon/orbited2/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ def _read_response(self, sock):
return buf

def _check_verb(self, line):
if line != "HTTP/1.1 101 Web Socket Protocol Handshake":
raise Exception("Invalid server handshake (verb line)")
# HTTP/1.1 101 Web Socket Protocol Handshake
# HTTP/1.1 101 WebSocket Protocol Handshake
if not line.startswith("HTTP/1.1 101 ") or "Web" not in line or "Socket" not in line or "Handshake" not in line:
# if line != "HTTP/1.1 101 Web Socket Protocol Handshake":
raise Exception("Invalid server handshake (verb line), %s" % (repr(line),))

def _check_upgrade(self, line):
if line != "Upgrade: WebSocket":
Expand Down Expand Up @@ -404,4 +407,4 @@ def handshake(self, sock):
raise Exception("Invalid server handshake (wrong 16 byte security key)")
self._buf = buf[16:]
def close(self, sock):
sock.sendall(self.pack_message(""))
sock.sendall(self.pack_message(""))
4 changes: 2 additions & 2 deletions tests/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

Orbited2.WebSocket.install({
orbitedUri: "http://127.0.0.1:8000",
protocolVersion: 'hixie76'
// forceProxy: true
});

var ws = null;
Expand All @@ -36,4 +36,4 @@
</head>
<body>
<h1>Orbited.Websocket test page</h1>
</body>
</body>