diff --git a/dput-webdav/debian/changelog b/dput-webdav/debian/changelog index c880a43..e7363a1 100644 --- a/dput-webdav/debian/changelog +++ b/dput-webdav/debian/changelog @@ -1,3 +1,9 @@ +dput-webdav (1.4.0) noplat; urgency=low + + * Sending Artifactory "X-Checksum-*" headers + + -- Juergen Hermann Fri, 17 Jun 2016 11:11:00 +0200 + dput-webdav (1.3.3) noplat; urgency=low * Fix: Use credentials for checks (read access), too (closes #6) diff --git a/dput-webdav/webdav.py b/dput-webdav/webdav.py index 34c9142..c235d7e 100644 --- a/dput-webdav/webdav.py +++ b/dput-webdav/webdav.py @@ -14,6 +14,7 @@ import socket import fnmatch import getpass +import hashlib import httplib import urllib2 import urlparse @@ -192,15 +193,15 @@ def _url_connection(url, method, skip_host=False, skip_accept_encoding=False): """Create HTTP[S] connection for `url`.""" scheme, netloc, path, params, query, _ = urlparse.urlparse(url) result = conn = (httplib.HTTPSConnection if scheme == "https" else httplib.HTTPConnection)(netloc) - conn.debuglevel = int(trace.debug) try: + conn.debuglevel = int(trace.debug) conn.putrequest(method, urlparse.urlunparse((None, None, path, params, query, None)), skip_host, skip_accept_encoding) conn.putheader("User-Agent", "dput") conn.putheader("Connection", "close") - conn = None + conn = None # return open connections as result finally: if conn: - conn.close() # close in case of errors + conn.close() # close in case of errors return result @@ -220,6 +221,15 @@ def _dav_put(filepath, url, matrix_params, login, progress=None): sys.stdout.flush() size = os.path.getsize(filepath) + hashes = dict([(x, getattr(hashlib, x)()) for x in ("md5", "sha1", "sha256")]) + with closing(open(filepath, 'r')) as handle: + while True: + data = handle.read(CHUNK_SIZE) + if not data: + break + for hashval in hashes.values(): + hashval.update(data) + with closing(open(filepath, 'r')) as handle: if progress: handle = dputhelper.FileWithProgress(handle, ptype=progress, progressf=sys.stdout, size=size) @@ -230,6 +240,8 @@ def _dav_put(filepath, url, matrix_params, login, progress=None): try: conn.putheader("Authorization", 'Basic %s' % login.encode('base64').replace('\n', '').strip()) conn.putheader("Content-Length", str(size)) + for algo, hashval in hashes.items(): + conn.putheader("X-Checksum-" + algo.capitalize(), hashval.hexdigest()) conn.endheaders() conn.debuglevel = 0