-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
30 lines (22 loc) · 1.08 KB
/
test.py
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
import requests
import time
base_url = 'https://d1zjsiun7w25x0.cloudfront.net'
paths = ['index.html', 'cat.html', 'dog.html', 'bird.html']
def test_cache_behavior(url, wait_time=15):
for path in paths:
full_url = f"{url}/{path}"
initial_response = requests.get(full_url)
etag = initial_response.headers.get('ETag')
print(f"Initial request for {path}: {initial_response.status_code}")
if etag:
hit_response = requests.get(full_url, headers={'If-None-Match': etag})
print(f"Cache hit test for {path}: {hit_response.status_code}")
else:
print(f"No ETag found for {path}")
print(f"Waiting {wait_time} seconds for cache to expire, to simulate a cache miss...")
time.sleep(wait_time)
print(f"After waiting {wait_time} seconds, making another request to simulate a cache miss.")
miss_response = requests.get(full_url)
print(f"Cache miss test for {path}: {miss_response.status_code}")
if __name__ == "__main__":
test_cache_behavior(base_url)