Skip to content

Commit 86bf31b

Browse files
authored
Merge pull request #107 from DrDaveD/curl-user-agent-no-proxy
Set User-Agent on stashcp's use of curl and unset http_proxy
2 parents ff35fe4 + 3c515c5 commit 86bf31b

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# For a discussion on single-sourcing the version across setup.py and the
4343
# project code, see
4444
# https://packaging.python.org/en/latest/single_source_version.html
45-
version='5.5.0', # Required
45+
version='5.5.1', # Required
4646

4747
# This is a one-line description or tagline of what your project does. This
4848
# corresponds to the "Summary" metadata field:

stashcp/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
from urlparse import urlparse
2525

2626
# Version information for user-agent
27-
VERSION = "5.5.0"
27+
VERSION = "5.5.1"
28+
29+
user_agent = 'stashcp/{0}'.format(VERSION)
2830

2931
main_redirector = "root://redirector.osgstorage.org"
3032
stash_origin = "root://stash.osgconnect.net"
@@ -59,12 +61,18 @@ def doWriteBack(source, destination):
5961
logging.error("Unable to find scitokens.use file")
6062
return 1
6163

64+
if debug:
65+
output_mode = "-v"
66+
else:
67+
output_mode = "-s"
68+
6269
# Check if the source file is zero-length
6370
statinfo = os.stat(source)
6471
if statinfo.st_size == 0:
65-
command = "curl -v --connect-timeout 30 --speed-time 5 --speed-limit 1024 -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
72+
speed_time = "--speed-time 5 "
6673
else:
67-
command = "curl -v --connect-timeout 30 --speed-limit 1024 -X PUT --fail --upload-file %s -H \"Authorization: Bearer %s\" %s%s" % (source, scitoken_contents, writeback_host, destination)
74+
speed_time = ""
75+
command = "curl %s --connect-timeout 30 %s--speed-limit 1024 -X PUT --fail --upload-file %s -H \"User-Agent: %s\" -H \"Authorization: Bearer %s\" %s%s" % (output_mode, speed_time, source, user_agent, scitoken_contents, writeback_host, destination)
6876

6977
if 'http_proxy' in os.environ:
7078
del os.environ['http_proxy']
@@ -390,12 +398,17 @@ def download_http(source, destination, debug, payload):
390398
if not parsed_url.port:
391399
cache += ":8000"
392400

401+
if 'http_proxy' in os.environ:
402+
# avoid caching big files in squid
403+
del os.environ['http_proxy']
404+
393405
# Quote the source URL, which may have weird, dangerous characters
394406
quoted_source = urllib2.quote(source)
395407
if scitoken_contents:
396-
curl_command = "curl %s -L --connect-timeout 30 --speed-limit 1024 %s --fail -H \"Authorization: Bearer %s\" %s%s" % (output_mode, download_output, scitoken_contents, cache, quoted_source)
408+
bearer_auth = "-H \"Authorization: Bearer %s\"" % (scitoken_contents)
397409
else:
398-
curl_command = "curl %s -L --connect-timeout 30 --speed-limit 1024 %s --fail %s%s" % (output_mode, download_output, cache, quoted_source)
410+
bearer_auth = ""
411+
curl_command = "curl %s -L --connect-timeout 30 --speed-limit 1024 %s --fail -H \"User-Agent: %s\" %s %s%s" % (output_mode, download_output, user_agent, bearer_auth, cache, quoted_source)
399412
logging.debug("About to run curl command: %s", curl_command)
400413
start = int(time.time()*1000)
401414
command_object = subprocess.Popen([curl_command], shell=True, cwd=dest_dir)
@@ -593,7 +606,7 @@ def get_best_stashcache():
593606
append_text = "api/v1.0/geo/stashcp"
594607

595608
# Headers for the HTTP request
596-
headers = {'Cache-control': 'max-age=0', 'User-Agent': 'stashcp/{0}'.format(VERSION) }
609+
headers = {'Cache-control': 'max-age=0', 'User-Agent': user_agent }
597610

598611
# Randomize the geo ip sites
599612
random.shuffle(geo_ip_sites)

0 commit comments

Comments
 (0)