Commit 980e1148 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5: check cache hit script enhanced to handle CSS and favicons

Previously, only images (from <img> tag) and scripts (from <script> tag) were handled
parent 76f2de1e
......@@ -191,7 +191,7 @@ output = ${buildout:directory}/template-http-monitor.cfg.in
< = download-base
url = ${:_profile_base_location_}/monitor-templates/monitor-check-cache-hit.in
download-only = true
md5sum = 878833710ffd2e0734989cb9c93a8103
md5sum = b9f3f93bc41287698a44a687e6483f01
filename = monitor-check-cache-hit.in
mode = 0644
......
......@@ -35,14 +35,23 @@ class MyHTMLParser(HTMLParser):
HTMLParser.__init__(self)
self.base_url = base_url
def handle_starttag(self, tag, attrs):
if tag == 'img' or tag == 'script': # TODO: CSS & JS
def handle_url(url):
if not url.startswith("http"):
url = self.base_url + url
do_request(url)
# handle images and js scripts
if tag == 'img' or tag == 'script':
debug(tag, attrs)
for attr in attrs:
if attr[0] == 'src':
url = attr[1]
if not url.startswith('http'):
url = self.base_url + url
do_request(url)
handle_url(attr[1])
# handle css and favicon
if tag == 'link' and \
any(attr[0] == "rel" and attr[1] in ("stylesheet", "shortcut icon") for attr in attrs):
debug(tag, attrs)
for attr in attrs:
if attr[0] == "href":
handle_url(attr[1])
headers = {
"User-Agent": "test",
......@@ -53,9 +62,7 @@ headers = {
}
url_list = {{ url_list }}
# url_list = ["http://www.erp5.com"]
resolve_list = {{ resolve_list }}
# resolve_list = ["www.erp5.com:80:5.135.149.226"]
parsed_url_dict = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment