Metadata-Version: 2.1
Name: requests_header_refresh
Version: 1.0.5
Summary: Adds support for the Refresh header in requests. Check out the README for more info.
Project-URL: Homepage, https://github.com/matthew-hajec/requests_header_refresh
Project-URL: Issues, https://github.com/matthew-hajec/requests_header_refresh/issues
Author-email: mhajec21 <matthew.hajec02@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: requests
Description-Content-Type: text/markdown

# Requests Header Refresh

## Description

This Python module provides a function to handle HTTP refresh headers in the `requests` library. It parses the refresh header, extracts or infers the refresh time and URL, and makes a subsequent request to the refresh URL if the refresh time is in a valid range. It also supports a maximum refresh to ignore the refresh if the refresh time is greater than a specified number of seconds.

## Installation

You can use this module by importing it in your Python script. Make sure to have the `requests-header-refresh` library installed in your environment. If not, you can install it using pip:

```bash
pip install requests-header-refresh
```

You will also need the [requests]('https://pypi.org/project/requests/') library to use this package.

## Usage

First, import the necessary functions and classes:

```python
import requests
from requests_header_refresh import create_hook
```

Then, create a session and a refresh handler with a timeout of 5 seconds:

```python
session = requests.Session()
refresh_hook = create_hook(max_refresh=5)
```

Add the handler as a response hook:

```python
session.hooks = {'response': [refresh_hook]}
```

Finally, make a request:

```python
response = session.get(url)
```

In this example, `refresh_hook` will ignore the refresh if the refresh time is greater than 5 seconds. Replace `url` with the actual URL you want to make a request to. Also, adjust the `max_refresh` based on your needs.


The hook could also be used for a single request instead of entire session:

```python
response = requests.get(url, hooks={'response': [refresh_hook]})
```

## Contributing

Contributions are welcome.