-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The issue_263.py script was in the ticket to provide a test.
I'm adding the script here for reference. I don't think the URL or scenario was especially unique, but it did exhibit the behavior and is worth keeping around for reference.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
|
||
import cachecontrol | ||
import requests | ||
from cachecontrol.cache import DictCache | ||
from cachecontrol.heuristics import BaseHeuristic | ||
|
||
import logging | ||
|
||
clogger = logging.getLogger("cachecontrol") | ||
clogger.addHandler(logging.StreamHandler()) | ||
clogger.setLevel(logging.DEBUG) | ||
|
||
|
||
from pprint import pprint | ||
|
||
|
||
class NoAgeHeuristic(BaseHeuristic): | ||
def update_headers(self, response): | ||
if "cache-control" in response.headers: | ||
del response.headers["cache-control"] | ||
|
||
|
||
cache_adapter = cachecontrol.CacheControlAdapter( | ||
DictCache(), cache_etags=True, heuristic=NoAgeHeuristic() | ||
) | ||
|
||
|
||
session = requests.Session() | ||
session.mount("https://", cache_adapter) | ||
|
||
|
||
def log_resp(resp): | ||
return | ||
|
||
print(f"{resp.status_code} {resp.request.method}") | ||
for k, v in response.headers.items(): | ||
print(f"{k}: {v}") | ||
|
||
|
||
for i in range(2): | ||
response = session.get( | ||
"https://api.github.com/repos/sigmavirus24/github3.py/pulls/1033" | ||
) | ||
log_resp(response) | ||
print(f"Content length: {len(response.content)}") | ||
print(response.from_cache) | ||
if len(response.content) == 0: | ||
sys.exit(1) |