Last active
November 10, 2023 13:30
-
-
Save maelvls/f71b6a9539a13d4fa7ff84d74491eb94 to your computer and use it in GitHub Desktop.
A mitmproxy script that makes sure the GET requests with ?watch=true (Kubernetes clients) are properly streamed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Enable the streaming mode [1] whenever a request contains the query | |
parameter ?watch=true. The watch=true parameter is passed by Kubernertes | |
clients (such as client-go) when they intend to be notified of object | |
updates. | |
Use with: | |
mitmproxy -p 9090 -s watch-stream.py | |
[1]: https://docs.mitmproxy.org/stable/overview-features/#streaming | |
""" | |
from mitmproxy import ctx, http | |
import mitmproxy.coretypes.multidict | |
def responseheaders(flow: http.HTTPFlow): | |
""" | |
Enables streaming for all requests that contain the query | |
param?watch=true. | |
""" | |
q: mitmproxy.coretypes.multidict.MultiDictView = flow.request.query | |
ctx.log.info("query params: " + q.__str__()) | |
watch = "" | |
try: | |
watch = q["watch"] | |
except KeyError as _: | |
pass | |
flow.response.stream = False | |
if watch == "true": | |
flow.response.stream = True | |
ctx.log.info("streaming request") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment