MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / HTTPChecker

Class HTTPChecker

scripts/fetch_updates.py:618–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616# ---------------------------------------------------------------------------
617
618class HTTPChecker:
619 def __init__(self, session: requests.Session, state: dict):
620 self.session = session
621 self.state = state
622
623 def check(self, source_id: str, source: dict) -> Optional[dict]:
624 url = source["url"]
625 prev = self.state.get(source_id, {})
626 headers = {}
627 if prev.get("etag"):
628 headers["If-None-Match"] = prev["etag"]
629 if prev.get("last_modified"):
630 headers["If-Modified-Since"] = prev["last_modified"]
631 try:
632 resp = self.session.head(url, headers=headers, timeout=15, allow_redirects=True)
633 new_state = {"url": url, "last_checked": datetime.now().isoformat(),
634 "status_code": resp.status_code}
635 if resp.headers.get("ETag"):
636 new_state["etag"] = resp.headers["ETag"]
637 if resp.headers.get("Last-Modified"):
638 new_state["last_modified"] = resp.headers["Last-Modified"]
639 self.state[source_id] = new_state
640 if resp.status_code == 304:
641 return None
642 elif resp.status_code == 200:
643 if prev.get("etag") and new_state.get("etag") == prev["etag"]:
644 return None
645 return _make_update(source_id, source, "http_head",
646 "Page may have been updated - manual review required")
647 else:
648 print(f" WARNING: HTTP {resp.status_code}")
649 return None
650 except requests.RequestException as e:
651 print(f" ERROR: {e}")
652 return None
653
654
655# ---------------------------------------------------------------------------

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected