-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests.py
More file actions
60 lines (46 loc) · 2.23 KB
/
requests.py
File metadata and controls
60 lines (46 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import socket
import urllib.request
Pragma = 'akamai-x-tapioca-trace,akamai-x-feo-trace, akamai-x-cache-on, akamai-x-cache-remote-on, \
akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, \
akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no, \
akamai-x-get-request-id'
headers = {'Pragma': Pragma}
#variables
final_result = {}
final_result['snc'] = 0
final_result['sac'] = 0
total_requests = 50
url = 'http://img.grouponcdn.com/deal/VAmXvXyNjkxBLhybuTVDq6uLjVH/VA-1000x600/v1/t220x134.jpg?cache_bust=true'
origin_1 = 'img-sac1.o.grouponcdn.com'
for i in range(total_requests):
try:
url = 'http://img.grouponcdn.com/deal/VAmXvXyNjkxBLhybuTVDq6uLjVH/VA-1000x600/v1/t220x134.jpg?cache_bust=true&count=' + str(i)
req = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(req)
#print(dir(response))
#print(response.getheaders())
session_info_List = response.getheader('X-Akamai-Session-Info').split(',')
#print(session_info_List)
for everySessionInfo in session_info_List:
name_value = everySessionInfo.split(';')
if name_value[0].strip() == 'name=PMUSER_ORIGIN_TO_USE':
print(name_value[1])
if origin_1 in name_value[1]:
final_result['sac'] += 1
else:
final_result['snc'] += 1
except urllib.error.HTTPError as HTTPError:
#print(HTTPError.headers)
session_info_List = HTTPError.getheader('X-Akamai-Session-Info').split(',')
#print(session_info_List)
for everySessionInfo in session_info_List:
name_value = everySessionInfo.split(';')
if name_value[0].strip() == 'name=PMUSER_ORIGIN_TO_USE':
print(' Error: ' + name_value[1])
if origin_1 in name_value[1]:
final_result['sac'] += 1
else:
final_result['snc'] += 1
print(' SAC: ' + str(final_result['sac']) + ' SNC: '+ str(final_result['snc']))
print('Total Origin_1 SAC Requests: ' + str(final_result['sac']) + '\n')
print('Total Origin_2 SNC Requests: ' + str(final_result['snc']) + '\n')