Skip to content

Commit

Permalink
The issue_263.py script was in the ticket to provide a test.
Browse files Browse the repository at this point in the history
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
ionrock committed Oct 31, 2021
1 parent d085f50 commit 0fa7749
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/issue_263.py
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)

0 comments on commit 0fa7749

Please sign in to comment.