From c2016ba03775e937a5b0cfee7e74264ced29a537 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 20 Apr 2020 10:09:13 +0000 Subject: [PATCH] avoid crashing ie --- copyparty/httpcli.py | 12 +++++++++--- copyparty/util.py | 6 +++--- copyparty/web/up2k.js | 17 ++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index fe5a280b..15bf4c30 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -144,7 +144,7 @@ class HttpCli(object): try: self.s.sendall(response_str + b"\r\n\r\n" + body) except: - raise Pebkac(400, "client disconnected before http response") + raise Pebkac(400, "client d/c before http response") return body @@ -200,7 +200,10 @@ class HttpCli(object): self.log("POST " + self.req) if self.headers.get("expect", "").lower() == "100-continue": - self.s.sendall(b"HTTP/1.1 100 Continue\r\n\r\n") + try: + self.s.sendall(b"HTTP/1.1 100 Continue\r\n\r\n") + except: + raise Pebkac(400, "client d/c before 100 continue") ctype = self.headers.get("content-type", "").lower() if not ctype: @@ -621,7 +624,10 @@ class HttpCli(object): headers.extend(extra_headers) headers = "\r\n".join(headers).encode("utf-8") + b"\r\n\r\n" - self.s.sendall(headers) + try: + self.s.sendall(headers) + except: + raise Pebkac(400, "client d/c before http response") if self.mode == "HEAD" or not do_send: self.log(logmsg) diff --git a/copyparty/util.py b/copyparty/util.py index 0fd94cc1..ae2e2bd8 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -190,7 +190,7 @@ class MultipartParser(object): buf = self.sr.recv(bufsz) if not buf: # abort: client disconnected - raise Pebkac(400, "client disconnected during multipart post") + raise Pebkac(400, "client d/c during multipart post") while True: ofs = buf.find(self.boundary) @@ -224,7 +224,7 @@ class MultipartParser(object): buf2 = self.sr.recv(bufsz) if not buf2: # abort: client disconnected - raise Pebkac(400, "client disconnected during multipart post") + raise Pebkac(400, "client d/c during multipart post") buf += buf2 @@ -421,7 +421,7 @@ def read_socket(sr, total_size): buf = sr.recv(bufsz) if not buf: - raise Pebkac(400, "client disconnected during binary post") + raise Pebkac(400, "client d/c during binary post") remains -= len(buf) yield buf diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index fd0dc30a..6b7ddf49 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -72,10 +72,9 @@ function opclick(ev) { var dest = this.getAttribute('data-dest'); goto(dest); - try { - localStorage.opmode = dest; - } - catch { } + // writing a blank value makes ie8 segfault w + if (window['localStorage']) + localStorage.setItem('opmode', dest || '.'); } @@ -108,11 +107,11 @@ function goto_up2k() { goto(); -try { - var op = localStorage.opmode; - goto(op); +if (window['localStorage']) { + var op = localStorage.getItem('opmode'); + if (op !== null && op !== '.') + goto(op); } -catch { } // chrome requires https to use crypto.subtle, @@ -217,7 +216,7 @@ function up2k_init(have_crypto) { if (val === null) return parseInt(o(name).value); - o(name).value = val + o(name).value = val; return val; }