Skip to content

Commit

Permalink
1.4.0: Sending Artifactory "X-Checksum-*" headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jhermann committed Jun 17, 2016
1 parent 8679808 commit b172cbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions dput-webdav/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dput-webdav (1.4.0) noplat; urgency=low

* Sending Artifactory "X-Checksum-*" headers

-- Juergen Hermann <[email protected]> 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)
Expand Down
18 changes: 15 additions & 3 deletions dput-webdav/webdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import socket
import fnmatch
import getpass
import hashlib
import httplib
import urllib2
import urlparse
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit b172cbe

Please sign in to comment.