Skip to main content

No project description provided

Project description

hteetp

PyPI - Version PyPI - Python Version

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

pip install hteetp

Usage

The simplest usage is hteetp.http_request:

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 teeing for you. This gives you a long-lived connection if you're hitting the same host many times.

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:

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)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hteetp-0.1.tar.gz (9.0 MB view details)

Uploaded Source

Built Distribution

hteetp-0.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file hteetp-0.1.tar.gz.

File metadata

  • Download URL: hteetp-0.1.tar.gz
  • Upload date:
  • Size: 9.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.0

File hashes

Hashes for hteetp-0.1.tar.gz
Algorithm Hash digest
SHA256 2c3f30b20d3ffa2cea8d8972301c0aad8dbc1ebaa5dfd7ac85365ee2d357fdc0
MD5 25df63346c6dd1831bc15857445977c6
BLAKE2b-256 73b75da70045dc90b7984f57a435f7bc7e9ce28b8c5fbe8b958420a696d0ded5

See more details on using hashes here.

File details

Details for the file hteetp-0.1-py3-none-any.whl.

File metadata

  • Download URL: hteetp-0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.0

File hashes

Hashes for hteetp-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f3d1183f2998cb58ae0cff905aa615492e5dcb4d6bd1c836605d19ec781966b
MD5 7bea73e3ca707c6993851a73d7c94802
BLAKE2b-256 f725ae6f886c4dbcb8f4a92feb5d7c310ff7f328e9d136127b9f8893bc7d417e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page