Skip to content

Conversation

@AndreyLebedev345
Copy link

Summary

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

AndreyLebedev345 and others added 5 commits October 7, 2025 19:40
Add documentation to is_ipv4_hostname and is_ipv6_hostname functions
to clarify their purpose and CIDR notation support.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Introduced a new helper function, is_ip_address, to check if a given hostname is a valid IP address (either IPv4 or IPv6), including support for CIDR notation. This enhances the utility of the IP validation module.
…ling

Introduced a new utility function, normalize_header_key, to standardize HTTP header keys for comparison and storage. This function normalizes keys to lowercase by default, with an option to preserve the original case for compatibility with HTTP/1.1. Updated __all__ to include the new function.
This commit adds two new convenience methods to the Response class:

1. json_or_text(): Attempts to parse the response as JSON, automatically
   falling back to text content if JSON parsing fails. This provides a
   convenient way to handle responses that may be in either format without
   explicit exception handling.

2. save_to_file(path, mode='auto'): Saves response content to a file with
   intelligent handling of different content types. Supports multiple modes:
   - 'auto': Automatically detects format based on Content-Type header
   - 'binary': Saves raw bytes (images, PDFs, etc.)
   - 'text': Saves as text with encoding support
   - 'json': Parses and saves formatted JSON with indentation

These methods enhance the Response API by providing commonly needed
functionality that previously required manual implementation. The
save_to_file method is particularly useful for downloading and storing
various types of content from web APIs and servers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant