| Name | hteetp JSON |
| Version |
0.1
JSON |
| download |
| home_page | None |
| Summary | None |
| upload_time | 2023-05-12 22:01:12 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.10 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# hteetp
[](https://pypi.org/project/hteetp)
[](https://pypi.org/project/hteetp)
`hteetp` is a Python package for copying HTTP responses to disk. It
provides wrappers around the standard library's `http.client`
infrastructure.
This is useful when making something that should capture traffic,
either for later analysis or for a cache.
It's like `tee` but for HTTP requests.
## Installation
```console
pip install hteetp
```
## Usage
The simplest usage is `hteetp.http_request`:
```python
from hteetp import http_request
def request_and_record():
response = http_request("./snapshot.http", "GET", "github.com", "/spenczar/hteetp")
# Now the file ./snapshot.http exists - but it will only have headers and the
# 'HTTP/1.1' preamble
response_data = response.read()
# Now the file will be populated with the contents of response_data
assert len(response.headers) > 0
assert len(response_data) != 0
```
### Long-lived connections
Alternatively, `hteetp.TeeHTTPConnection` is a replacement for
`http.client.HTTPConnection`. You provide it with a function for
generating filepaths given HTTP request parameters, and it manages the
`tee`ing for you. This gives you a long-lived connection if you're
hitting the same host many times.
```python
from hteetp import TeeHTTPConnection, relative_files
def request_and_record():
conn = TeeHTTPConnection(relative_files("./snapshots") "github.com")
for path in ["/spenczar/hteetp", "/python/cpython", "/psf/requests"]:
resp = conn.request("GET", path)
resp_data = resp.read()
# handle each response
# The following files will have been written:
# ./snapshots/GET/github.com:443/spenczar/hteetp
# ./snapshots/GET/github.com:443/python/cpython
# ./snapshots/GET/github.com:443/psf/requests
```
### Reading HTTP from files on disk
`hteetp.http_response_from_file` is a little utility for loading a
`http.client.HTTPResponse` from a file on disk:
```python
from hteetp import http_response_from_file
resp = http_response_from_file("./snapshots/GET/github.com:443/spenczar/hteetp")
print(resp.headers)
resp_body = resp.read()
print(resp_body)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "hteetp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Spencer Nelson <spencer@b612foundation.org>",
"download_url": "https://files.pythonhosted.org/packages/73/b7/5da70045dc90b7984f57a435f7bc7e9ce28b8c5fbe8b958420a696d0ded5/hteetp-0.1.tar.gz",
"platform": null,
"description": "# hteetp\n\n[](https://pypi.org/project/hteetp)\n[](https://pypi.org/project/hteetp)\n\n`hteetp` is a Python package for copying HTTP responses to disk. It\nprovides wrappers around the standard library's `http.client`\ninfrastructure.\n\nThis is useful when making something that should capture traffic,\neither for later analysis or for a cache.\n\nIt's like `tee` but for HTTP requests.\n\n## Installation\n\n```console\npip install hteetp\n```\n\n## Usage\n\nThe simplest usage is `hteetp.http_request`:\n\n```python\nfrom hteetp import http_request\n\n\ndef request_and_record():\n\tresponse = http_request(\"./snapshot.http\", \"GET\", \"github.com\", \"/spenczar/hteetp\")\n\t# Now the file ./snapshot.http exists - but it will only have headers and the \n\t# 'HTTP/1.1' preamble\n\t\n\tresponse_data = response.read()\n\t# Now the file will be populated with the contents of response_data\n\t\n\tassert len(response.headers) > 0\n\tassert len(response_data) != 0\n```\n\n\n### Long-lived connections\n\nAlternatively, `hteetp.TeeHTTPConnection` is a replacement for\n`http.client.HTTPConnection`. You provide it with a function for\ngenerating filepaths given HTTP request parameters, and it manages the\n`tee`ing for you. This gives you a long-lived connection if you're\nhitting the same host many times.\n\n```python\nfrom hteetp import TeeHTTPConnection, relative_files\n\n\ndef request_and_record():\n\tconn = TeeHTTPConnection(relative_files(\"./snapshots\") \"github.com\")\n\tfor path in [\"/spenczar/hteetp\", \"/python/cpython\", \"/psf/requests\"]:\n\t\tresp = conn.request(\"GET\", path)\n\t\tresp_data = resp.read()\n\t\t# handle each response\n\t# The following files will have been written:\n\t# ./snapshots/GET/github.com:443/spenczar/hteetp\n\t# ./snapshots/GET/github.com:443/python/cpython\t\n\t# ./snapshots/GET/github.com:443/psf/requests\t\n\n```\n\n\n### Reading HTTP from files on disk\n\n`hteetp.http_response_from_file` is a little utility for loading a\n`http.client.HTTPResponse` from a file on disk:\n\n```python\nfrom hteetp import http_response_from_file\n\nresp = http_response_from_file(\"./snapshots/GET/github.com:443/spenczar/hteetp\")\nprint(resp.headers)\nresp_body = resp.read()\nprint(resp_body)\n```\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.1",
"project_urls": {
"Documentation": "https://github.com/unknown/hteetp#readme",
"Issues": "https://github.com/unknown/hteetp/issues",
"Source": "https://github.com/unknown/hteetp"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f725ae6f886c4dbcb8f4a92feb5d7c310ff7f328e9d136127b9f8893bc7d417e",
"md5": "7bea73e3ca707c6993851a73d7c94802",
"sha256": "0f3d1183f2998cb58ae0cff905aa615492e5dcb4d6bd1c836605d19ec781966b"
},
"downloads": -1,
"filename": "hteetp-0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7bea73e3ca707c6993851a73d7c94802",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 7984,
"upload_time": "2023-05-12T22:01:08",
"upload_time_iso_8601": "2023-05-12T22:01:08.779763Z",
"url": "https://files.pythonhosted.org/packages/f7/25/ae6f886c4dbcb8f4a92feb5d7c310ff7f328e9d136127b9f8893bc7d417e/hteetp-0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "73b75da70045dc90b7984f57a435f7bc7e9ce28b8c5fbe8b958420a696d0ded5",
"md5": "25df63346c6dd1831bc15857445977c6",
"sha256": "2c3f30b20d3ffa2cea8d8972301c0aad8dbc1ebaa5dfd7ac85365ee2d357fdc0"
},
"downloads": -1,
"filename": "hteetp-0.1.tar.gz",
"has_sig": false,
"md5_digest": "25df63346c6dd1831bc15857445977c6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 9019974,
"upload_time": "2023-05-12T22:01:12",
"upload_time_iso_8601": "2023-05-12T22:01:12.182196Z",
"url": "https://files.pythonhosted.org/packages/73/b7/5da70045dc90b7984f57a435f7bc7e9ce28b8c5fbe8b958420a696d0ded5/hteetp-0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-12 22:01:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "unknown",
"github_project": "hteetp#readme",
"github_not_found": true,
"lcname": "hteetp"
}