Skip to content

Commit efb006f

Browse files
committed
add User-Agent to curl call, unset http_proxy
1 parent ff35fe4 commit efb006f

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

stashcp/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# Version information for user-agent
2727
VERSION = "5.5.0"
2828

29+
user_agent = 'stashcp/{0}'.format(VERSION)
30+
2931
main_redirector = "root://redirector.osgstorage.org"
3032
stash_origin = "root://stash.osgconnect.net"
3133
writeback_host = "http://stash-xrd.osgconnect.net:1094"
@@ -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)