From 00ff133387b1c6aa7f74ad1ef36b2137c2a57fb3 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 25 Feb 2021 22:26:03 +0100 Subject: [PATCH] support receiving chunked PUT --- README.md | 13 +++++++++++++ copyparty/httpcli.py | 7 +++++-- copyparty/util.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c73192d..a984e84e 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,23 @@ other metadata (like song tags etc) are not yet indexed for searching * `await fetch('https://127.0.0.1:3923/', {method:"PUT", body: JSON.stringify(foo)});` * `var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://127.0.0.1:3923/msgs?raw'); xhr.send('foo');` +* curl/wget: upload some files (post=file, chunk=stdin) + * `post(){ curl -b cppwd=wark http://127.0.0.1:3923/ -F act=bput -F f=@"$1";}` + `post movie.mkv` + * `post(){ wget --header='Cookie: cppwd=wark' http://127.0.0.1:3923/?raw --post-file="$1" -O-;}` + `post movie.mkv` + * `chunk(){ curl -b cppwd=wark http://127.0.0.1:3923/ -T-;}` + `chunk 16: + err = err.format(buf.decode("utf-8", "replace"), len(buf)) + raise Pebkac(400, err) + + buf += rbuf + + if not buf.endswith(b"\n"): + sr.recv(1) + + try: + chunklen = int(buf.rstrip(b"\r\n"), 16) + except: + err = err.format(buf.decode("utf-8", "replace"), len(buf)) + raise Pebkac(400, err) + + if chunklen == 0: + sr.recv(2) # \r\n after final chunk + return + + if log: + log("receiving {} byte chunk".format(chunklen)) + + for chunk in read_socket(sr, chunklen): + yield chunk + + sr.recv(2) # \r\n after each chunk too + + def hashcopy(actor, fin, fout): u32_lim = int((2 ** 31) * 0.9) hashobj = hashlib.sha512()