Skip to content

Instantly share code, notes, and snippets.

@justinmeiners
justinmeiners / python3_caching_proxy.py
Last active February 9, 2023 17:17
A simple caching HTTP proxy in Python 3.
# A simple HTTP proxy which does caching of requests.
# Inspired by: https://gist.github.com/bxt/5195500
# but updated for Python 3 and some additional sanity improvements:
# - shutil is used to serve files in a streaming manner, so the entire data is not loaded into memory.
# - the http request is written to a temp file and renamed on success
# - forward headers
import http.server
import socketserver
import urllib.request