|
26 | 26 | # Version information for user-agent |
27 | 27 | VERSION = "5.5.0" |
28 | 28 |
|
| 29 | +user_agent = 'stashcp/{0}'.format(VERSION) |
| 30 | + |
29 | 31 | main_redirector = "root://redirector.osgstorage.org" |
30 | 32 | stash_origin = "root://stash.osgconnect.net" |
31 | 33 | writeback_host = "http://stash-xrd.osgconnect.net:1094" |
@@ -59,12 +61,18 @@ def doWriteBack(source, destination): |
59 | 61 | logging.error("Unable to find scitokens.use file") |
60 | 62 | return 1 |
61 | 63 |
|
| 64 | + if debug: |
| 65 | + output_mode = "-v" |
| 66 | + else: |
| 67 | + output_mode = "-s" |
| 68 | + |
62 | 69 | # Check if the source file is zero-length |
63 | 70 | statinfo = os.stat(source) |
64 | 71 | 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 " |
66 | 73 | 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) |
68 | 76 |
|
69 | 77 | if 'http_proxy' in os.environ: |
70 | 78 | del os.environ['http_proxy'] |
@@ -390,12 +398,17 @@ def download_http(source, destination, debug, payload): |
390 | 398 | if not parsed_url.port: |
391 | 399 | cache += ":8000" |
392 | 400 |
|
| 401 | + if 'http_proxy' in os.environ: |
| 402 | + # avoid caching big files in squid |
| 403 | + del os.environ['http_proxy'] |
| 404 | + |
393 | 405 | # Quote the source URL, which may have weird, dangerous characters |
394 | 406 | quoted_source = urllib2.quote(source) |
395 | 407 | 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) |
397 | 409 | 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) |
399 | 412 | logging.debug("About to run curl command: %s", curl_command) |
400 | 413 | start = int(time.time()*1000) |
401 | 414 | command_object = subprocess.Popen([curl_command], shell=True, cwd=dest_dir) |
@@ -593,7 +606,7 @@ def get_best_stashcache(): |
593 | 606 | append_text = "api/v1.0/geo/stashcp" |
594 | 607 |
|
595 | 608 | # 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 } |
597 | 610 |
|
598 | 611 | # Randomize the geo ip sites |
599 | 612 | random.shuffle(geo_ip_sites) |
|
0 commit comments