url
plantdb.client.url Link
Robust server‑availability checker with built‑in SSRF / safety guards.
ServerCheckResult
dataclass
Link
ServerCheckResult(url, status_code, ok, final_url, message, n_redirects=0)
Class containing information about the server's response.
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 |
|---|---|---|---|
url
|
str
|
The URL of the server to check. |
required |
timeout
|
float
|
Maximum number of seconds to wait for a response. Default is |
5.0
|
max_redirects
|
int
|
Maximum number of redirects to follow. Default is |
2
|
max_retries
|
int
|
Maximum number of retries in case of failure. Default is |
3
|
backoff_factor
|
float
|
Multiplier for the delay between retry attempts. Default is |
0.3
|
allow_private_ip
|
bool
|
If |
False
|
validate_host
|
bool
|
Whether to validate the hostname against a whitelist/blacklist. Default is |
True
|
cert_path
|
str or Path
|
Path to a CA bundle to use. Default is |
None
|
verify_ssl
|
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
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 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 | |