This commit is contained in:
Robert Sayre 2010-07-29 13:13:21 -07:00
Родитель 3a26720a0b c9964e0a70
Коммит d3f6d23c8b
5 изменённых файлов: 12 добавлений и 73 удалений

Просмотреть файл

@ -388,24 +388,21 @@ function FindProxyForURL(url, host)
return 'DIRECT'; return 'DIRECT';
var isHttp = matches[1] == 'http'; var isHttp = matches[1] == 'http';
var isHttps = matches[1] == 'https'; var isHttps = matches[1] == 'https';
var isWs = matches[1] == 'ws'; var isWebSocket = matches[1] == 'ws';
var isWss = matches[1] == 'wss';
if (!matches[3]) if (!matches[3])
{ {
if (isHttp | isWs) matches[3] = '80'; if (isHttp | isWebSocket) matches[3] = '80';
if (isHttps | isWss) matches[3] = '443'; if (isHttps) matches[3] = '443';
} }
if (isWs) if (isWebSocket)
matches[1] = 'http'; matches[1] = 'http';
if (isWss)
matches[1] = 'https';
var origin = matches[1] + '://' + matches[2] + ':' + matches[3]; var origin = matches[1] + '://' + matches[2] + ':' + matches[3];
if (origins.indexOf(origin) < 0) if (origins.indexOf(origin) < 0)
return 'DIRECT'; return 'DIRECT';
if (isHttp) if (isHttp)
return 'PROXY %(remote)s:%(httpport)s'; return 'PROXY %(remote)s:%(httpport)s';
if (isHttps || isWs || isWss) if (isHttps || isWebSocket)
return 'PROXY %(remote)s:%(sslport)s'; return 'PROXY %(remote)s:%(sslport)s';
return 'DIRECT'; return 'DIRECT';
}""" % { "origins": origins, }""" % { "origins": origins,

Просмотреть файл

@ -396,7 +396,6 @@ _TEST_FILES2 = \
test_bug571390.xul \ test_bug571390.xul \
test_bug300992.html \ test_bug300992.html \
test_websocket_hello.html \ test_websocket_hello.html \
test_websocket_ssl_hello.html \
file_websocket_hello_wsh.py \ file_websocket_hello_wsh.py \
test_ws_basic_tests.html \ test_ws_basic_tests.html \
file_ws_basic_tests_wsh.py \ file_ws_basic_tests_wsh.py \

Просмотреть файл

@ -4,10 +4,7 @@ def web_socket_do_extra_handshake(request):
pass pass
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
resp = "Fail" resp = "Test"
request_text = msgutil.receive_message(request) if msgutil.receive_message(request) == "data":
if request_text == "data":
resp = "Hello world!" resp = "Hello world!"
elif request_text == "ssltest":
resp = "ssldata"
msgutil.send_message(request, resp) msgutil.send_message(request, resp)

Просмотреть файл

@ -1,50 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Basic websocket test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="testWebSocket()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=472529">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var ws;
function testWebSocket () {
ws = new WebSocket("wss://example.com:443/tests/content/base/test/file_websocket_hello");
ws.onopen = function(e) {
ws.send("ssltest");
}
ws.onclose = function(e) {
}
ws.onerror = function(e) {
is(false, "onerror called!");
SimpleTest.finish();
}
ws.onmessage = function(e) {
is(e.data, "ssldata");
ws.close();
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<div>
</div>
</body>
</html>

Просмотреть файл

@ -382,13 +382,13 @@ bool AdjustWebSocketLocation(relayBuffer& buffer, connection_info_t *ci)
char* wsloc = strstr(buffer.bufferhead, "Sec-WebSocket-Location:"); char* wsloc = strstr(buffer.bufferhead, "Sec-WebSocket-Location:");
if (!wsloc) if (!wsloc)
return true; return true;
// advance pointer to the start of the url, which will always start with // advance pointer to the start of the hostname
// ws://, since pywebsocket is ignorant of whether SSL is being used or not
wsloc = strstr(wsloc, "ws://"); wsloc = strstr(wsloc, "ws://");
if (!wsloc) if (!wsloc)
return false; return false;
wsloc += 5;
// find the end of the hostname // find the end of the hostname
char* wslocend = strchr(wsloc + 5, '/'); char* wslocend = strchr(wsloc + 1, '/');
if (!wslocend) if (!wslocend)
return false; return false;
char *crlf = strstr(wsloc, "\r\n"); char *crlf = strstr(wsloc, "\r\n");
@ -397,17 +397,13 @@ bool AdjustWebSocketLocation(relayBuffer& buffer, connection_info_t *ci)
if (ci->original_host.empty()) if (ci->original_host.empty())
return true; return true;
// generate a new hostname, beginning either with ws:// or wss://, int diff = ci->original_host.length() - (wslocend-wsloc);
// as appropriate, depending on whether this connection is using SSL
string newhost = (ci->http_proxy_only ? "ws://" : "wss://");
newhost.append(ci->original_host);
int diff = newhost.length() - (wslocend-wsloc);
if (diff > 0) if (diff > 0)
assert(size_t(diff) <= buffer.margin()); assert(size_t(diff) <= buffer.margin());
memmove(wslocend + diff, wslocend, buffer.buffertail - wsloc - diff); memmove(wslocend + diff, wslocend, buffer.buffertail - wsloc - diff);
buffer.buffertail += diff; buffer.buffertail += diff;
memcpy(wsloc, newhost.c_str(), newhost.length()); memcpy(wsloc, ci->original_host.c_str(), ci->original_host.length());
return true; return true;
} }