Skip to content

Commit

Permalink
#1568 websocket and rfb fixes
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@17091 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 3, 2017
1 parent fee4234 commit 76e42ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/xpra/net/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import os
import zlib
import posixpath
import urllib
try:
from urllib import unquote #python2 @UnusedImport
except:
from urllib.parse import unquote #python3 @Reimport @UnresolvedImport

from xpra.log import Logger
log = Logger("network", "websocket")
Expand Down Expand Up @@ -49,7 +52,7 @@ def translate_path(self, path):
path = path.split('#',1)[0]
# Don't forget explicit trailing slash when normalizing. Issue17324
trailing_slash = path.rstrip().endswith('/')
path = posixpath.normpath(urllib.unquote(path))
path = posixpath.normpath(unquote(path))
words = path.split('/')
words = filter(None, words)
path = self.web_root or "/usr/share/xpra/www"
Expand Down Expand Up @@ -87,7 +90,7 @@ def end_headers(self):
path = getattr(self, "path", "")
if path.endswith("?echo-headers"):
#ie: "en-GB,en-US;q=0.8,en;q=0.6"
accept = self.headers.getheader("Accept-Language")
accept = self.headers.get("Accept-Language")
if accept:
self.send_header("Echo-Accept-Language", std(accept, extras="-,./:;="))
if HTTP_NOCACHE:
Expand All @@ -102,7 +105,7 @@ def send_nocache_headers(self):

def do_POST(self):
try:
length = int(self.headers.getheader('content-length'))
length = int(self.headers.get('content-length'))
data = self.rfile.read(length)
log("POST data=%s (%i bytes)", data, length)
self.handle_request()
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/server/rfb/rfb_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def init(self):


def _get_rfb_desktop_model(self):
models = self._window_to_id.keys()
models = tuple(self._window_to_id.keys())
if len(models)!=1:
log.error("RFB can only handle a single desktop window, found %i", len(self._window_to_id))
return None
return models[0]

def _get_rfb_desktop_wid(self):
ids = self._window_to_id.values()
ids = tuple(self._window_to_id.values())
if len(ids)!=1:
log.error("RFB can only handle a single desktop window, found %i", len(self._window_to_id))
return None
Expand Down
29 changes: 16 additions & 13 deletions src/xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,9 @@ def guess_header_protocol(self, v):
c = int(v[0])
if c==0x16:
return "SSL", "SSL packet?"
elif len(v)>=3 and v.split(" ")[0] in ("GET", "POST"):
return "HTTP", "HTTP %s request" % v.split(" ")[0]
s = bytestostr(v)
if len(s)>=3 and s.split(" ")[0] in ("GET", "POST"):
return "HTTP", "HTTP %s request" % s.split(" ")[0]
return None, "character %#x, not an xpra client?" % c


Expand All @@ -977,7 +978,7 @@ def start_http_socket(self, conn, is_ssl=False, peek_data=""):
line1 = peek_data.splitlines()[0]
http_proto = "http"+["","s"][int(is_ssl)]
if line1.startswith(b"GET ") or line1.startswith(b"POST "):
parts = line1.split(" ")
parts = bytestostr(line1).split(" ")
httplog("New %s %s request received from %s for '%s'", http_proto, parts[0], frominfo, parts[1])
tname = "%s-request" % parts[0]
req_info = "%s %s" % (http_proto, parts[0])
Expand All @@ -999,16 +1000,18 @@ def new_websocket_client(wsh):
wslog("new_websocket_client(%s) socket=%s", wsh, sock)
wsc = WebSocketConnection(sock, conn.local, conn.remote, conn.target, conn.socktype, wsh)
# we need this workaround for non-blocking sockets
from xpra.net.bytestreams import untilConcludes
saved_recv = sock.recv
saved_send = sock.send
#now we can have a "is_active" that belongs to the real connection object:
def recv(*args):
return untilConcludes(wsc.is_active, wsc.can_retry, saved_recv, *args)
def send(*args):
return untilConcludes(wsc.is_active, wsc.can_retry, saved_send, *args)
sock.recv = recv
sock.send = send
# TODO: python3 will need a different solution
if not PYTHON3:
from xpra.net.bytestreams import untilConcludes
saved_recv = sock.recv
saved_send = sock.send
#now we can have a "is_active" that belongs to the real connection object:
def recv(*args):
return untilConcludes(wsc.is_active, wsc.can_retry, saved_recv, *args)
def send(*args):
return untilConcludes(wsc.is_active, wsc.can_retry, saved_send, *args)
sock.recv = recv
sock.send = send
socktype = "ws%s" % ["","s"][int(is_ssl)]
self.make_protocol(socktype, wsc)
scripts = self.get_http_scripts()
Expand Down

0 comments on commit 76e42ee

Please sign in to comment.