Last active
October 5, 2025 21:11
-
-
Save srcreigh/2bc8687aace702698d4b8b0b51637bc5 to your computer and use it in GitHub Desktop.
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
| import json | |
| import traceback | |
| from mitmproxy import ctx, http | |
| def response(flow: http.HTTPFlow) -> None: | |
| assert flow.response is not None | |
| assert flow.response.content is not None | |
| if (flow.request.method, flow.request.host) != ("POST", "gql-fed.reddit.com"): | |
| return | |
| if flow.response.status_code != 200: | |
| return | |
| try: | |
| op = flow.request.json()['operationName'] | |
| data = flow.response.json() | |
| if op in {"HomeFeedSdui", "SubredditFeedSdui", "PopularFeedSdui", "NewsFeedSdui"}: | |
| collection_name = {"HomeFeedSdui": "homeV3", | |
| "SubredditFeedSdui": "subredditV3", | |
| "PopularFeedSdui": "popularV3", | |
| "NewsFeedSdui": "newsV3"}[op] | |
| elements = data['data'][collection_name]['elements'] | |
| elements['edges'] = [ | |
| edge for edge in elements['edges'] | |
| if not any( | |
| cell['__typename'] == 'AdMetadataCell' | |
| for cell in edge['node'].get('cells', []))] | |
| elif op == "HomeFeedElements": | |
| elements = data['data']['home']['elements'] | |
| elements['edges'] = [ | |
| edge for edge in elements['edges'] | |
| if edge['node']['__typename'] != 'AdPost'] | |
| elif op == "PdpCommentsAds": | |
| data['data']['postInfoById']['pdpCommentsAds']['adPosts'] = [] | |
| flow.response.content = json.dumps(data).encode() | |
| except Exception as e: | |
| ctx.log.error(f"Error processing Reddit response: {e}\n{traceback.format_exc()}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I set it up in mitm docker but could not get it working with following errors, what went wrong here?
[21:05:24.534][192.168.1.108:60853] error establishing server connection: Multiple exceptions: [Errno 111] Connect call failed ('0.0.0.0', 443), [Errno 111] Connect call failed ('::', 443, 0, 0)
[21:05:24.535][192.168.1.108:60854] error establishing server connection: Multiple exceptions: [Errno 111] Connect call failed ('0.0.0.0', 443), [Errno 111] Connect call failed ('::', 443, 0, 0)
[21:05:24.538][192.168.1.108:60853] client disconnect
[21:05:24.539][192.168.1.108:60854] client disconnect
[21:05:27.115][192.168.1.108:60855] client connect
[21:05:27.205][192.168.1.108:60855] server connect gql-fed.reddit.com:443 (199.232.37.140:443)
[21:05:27.246][192.168.1.108:60855] Client TLS handshake failed. The client disconnected during the handshake. If this happens consistently for gql-fed.reddit.com, this may indicate that the client does not trust the proxy's certificate.
[21:05:27.246][192.168.1.108:60855] client disconnect
[21:05:27.247][192.168.1.108:60855] server disconnect gql-fed.reddit.com:443 (199.232.37.140:443)
[21:05:27.259][192.168.1.108:60856] client connect
[21:05:27.261][192.168.1.108:60857] client connect
[21:05:27.266][192.168.1.108:60856] error establishing server connection: Multiple exceptions: [Errno 111] Connect call failed ('0.0.0.0', 443), [Errno 111] Connect call failed ('::', 443, 0, 0)
[21:05:27.268][192.168.1.108:60857] error establishing server connection: Multiple exceptions: [Errno 111] Connect call failed ('0.0.0.0', 443), [Errno 111] Connect call failed ('::', 443, 0, 0)
[21:05:27.270][192.168.1.108:60856] client disconnect
[21:05:27.273][192.168.1.108:60857] client disconnect
[21:05:28.875][192.168.1.108:60858] client connect
[21:05:28.897][192.168.1.108:60858] server connect gql-fed.reddit.com:443 (199.232.89.140:443)