Skip to content

Commit 8def1fa

Browse files
authored
Merge pull request #34 from djw8605/http_geoip
HTTP Request
2 parents 09f4cd6 + 9fbb68e commit 8def1fa

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

bin/stashcp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ DIFF = TIMEOUT * 10
2424

2525
def doStashCpSingle(sourceFile, destination, cache, debug=False):
2626

27-
2827
#cache=get_best_stashcache()
2928
logging.debug("Using Cache %s", cache)
3029

@@ -293,7 +292,10 @@ def get_best_stashcache():
293292
geo_ip_sites.insert(0,"http://hcc-cvmfs.unl.edu:8000/cvmfs/config-osg.opensciencegrid.org")
294293

295294
# Append text before caches string
296-
append_text = "api/v1.0/geo/@proxy@"
295+
append_text = "api/v1.0/geo/stashcp"
296+
297+
# Headers for the HTTP request
298+
headers = {'Cache-control': 'max-age=0', 'User-Agent': 'stashcp/4.3.1'}
297299

298300
# Randomize the geo ip sites
299301
random.shuffle(geo_ip_sites)
@@ -305,7 +307,9 @@ def get_best_stashcache():
305307
final_url = "%s/%s/%s" % (cur_site, append_text, caches_string)
306308
logging.debug("Querying for closest cache: %s", final_url)
307309
try:
308-
response = urllib2.urlopen(final_url)
310+
# Make the request
311+
req = urllib2.Request(final_url, headers=headers)
312+
response = urllib2.urlopen(req)
309313
if response.getcode() == 200:
310314
logging.debug("Got error code 200 from %s", cur_site)
311315
found = True

0 commit comments

Comments
 (0)