url
Server Availability CheckerLink
A robust utility for verifying the reachability of HTTP(S) endpoints while protecting against SSRF attacks. It validates URLs, enforces whitelist/blacklist policies, filters private networks, resolves hostnames securely, and performs configurable HTTP requests with retry, timeout, and SSL handling.
Key FeaturesLink
- Strict URL scheme validation (only
httpandhttps) - Optional whitelist loading from a file and dynamic blacklist caching from GitHub
- Private‑network and blacklisted‑host protection
- DNS‑over‑HTTPS resolution with fallback to the system resolver
- Customizable SSL context with optional custom CA bundles
- Manual redirect handling with a configurable limit
- Retry strategy with exponential back‑off and timeout control
- Dataclass
ServerCheckResultsummarizing status, final URL, redirects, and messages
Usage ExamplesLink
>>> from plantdb.client.url import is_server_available
>>> result = is_server_available('https://example.com', validate_host=False)
>>> print(result.ok, result.final_url)
True https://example.com/
-
Reference API
client
client
rest_api
urls
origin_url
ServerCheckResult
dataclass
Link
ServerCheckResult(url, status_code, ok, final_url, message, n_redirects=0)
Class containing information about the server's response.
-
Reference API
client
client
url
is_server_available
is_server_available
Link
is_server_available(url, timeout=5.0, max_redirects=2, max_retries=3, backoff_factor=0.3, allow_private_ip=False, validate_host=True, cert_path=None, verify_ssl=True)
Check if a server is available by making an HTTP request to the given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The URL of the server to check. |
required |
|
float
|
Maximum number of seconds to wait for a response. Default is |
5.0
|
|
int
|
Maximum number of redirects to follow. Default is |
2
|
|
int
|
Maximum number of retries in case of failure. Default is |
3
|
|
float
|
Multiplier for the delay between retry attempts. Default is |
0.3
|
|
bool
|
If |
False
|
|
bool
|
Whether to validate the hostname against a whitelist/blacklist. Default is |
True
|
|
str or Path
|
Path to a CA bundle to use. Default is |
None
|
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
Returns:
| Type | Description |
|---|---|
ServerCheckResult
|
An object containing details about the server check result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied URL is malformed or a redirect target is invalid. |
RuntimeError
|
If the maximum redirect limit is exceeded. |
ConnectionError
|
If the HTTP request fails due to network issues. |
Examples:
>>> from plantdb.client.url import is_server_available
>>> scr = is_server_available('https://google.com', validate_host=False)
>>> print(scr.final_url)
https://www.google.com/
>>> scr = is_server_available('https://google.com', validate_host=True)
INFO [url] Validating URL hostname: google.com...
INFO [url] Validating URL hostname: www.google.com...
print(scr.ok)
True
Source code in plantdb/client/url.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | |