diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 919b0b5a..3a9351b3 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -769,11 +769,18 @@ class HttpCli(object): else: upper = file_sz - if lower < 0 or lower >= file_sz or upper < 0 or upper > file_sz: + if upper > file_sz: + upper = file_sz + + if lower < 0 or lower >= upper: raise Exception() except: - raise Pebkac(400, "invalid range requested: " + hrange) + err = "invalid range ({}), size={}".format(hrange, file_sz) + self.loud_reply(err, status=416, headers={ + "Content-Range": "bytes */{}".format(file_sz) + }) + return True status = 206 self.out_headers["Content-Range"] = "bytes {}-{}/{}".format( diff --git a/copyparty/util.py b/copyparty/util.py index ceaeabcc..097fcbf8 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -49,6 +49,7 @@ HTTPCODE = { 404: "Not Found", 405: "Method Not Allowed", 413: "Payload Too Large", + 416: "Requested Range Not Satisfiable", 422: "Unprocessable Entity", 500: "Internal Server Error", 501: "Not Implemented", diff --git a/docs/notes.sh b/docs/notes.sh index d756a760..c961ea57 100644 --- a/docs/notes.sh +++ b/docs/notes.sh @@ -80,3 +80,22 @@ for d in /usr /var; do find $d -type f -size +30M 2>/dev/null; done | while IFS= # py2 on osx brew install python@2 pip install virtualenv + + +## +## http 206 + +# az = abcdefghijklmnopqrstuvwxyz + +printf '%s\r\n' 'GET /az HTTP/1.1' 'Host: ocv.me' 'Range: bytes=5-10' '' | ncat ocv.me 80 +# Content-Range: bytes 5-10/26 +# Content-Length: 6 +# fghijk + +Range: bytes=0-1 "ab" Content-Range: bytes 0-1/26 +Range: bytes=24-24 "y" Content-Range: bytes 24-24/26 +Range: bytes=24-25 "yz" Content-Range: bytes 24-25/26 +Range: bytes=24- "yz" Content-Range: bytes 24-25/26 +Range: bytes=25-29 "z" Content-Range: bytes 25-25/26 +Range: bytes=26- Content-Range: bytes */26 + HTTP/1.1 416 Requested Range Not Satisfiable