Created
July 29, 2015 19:46
-
-
Save Mic92/5ef08e8d535d42a13360 to your computer and use it in GitHub Desktop.
This file contains 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
from libmproxy.protocol.http import decoded | |
import socket | |
import select | |
import threading | |
TCP_IP = '127.0.0.1' | |
TCP_PORT = 10000 | |
BUFFER_SIZE = 1024 | |
listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
listen.bind((TCP_IP, TCP_PORT)) | |
listen.listen(1) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((TCP_IP, TCP_PORT)) | |
def process(): | |
while True: | |
try: | |
select.select([listen], [listen], []) | |
conn, addr = listen.accept() | |
while True: | |
data = conn.recv(BUFFER_SIZE) | |
if not data: break | |
except: | |
pass | |
t = threading.Thread(target=process) | |
t.start() | |
def response(context, flow): | |
if flow.response.headers.get_first("content-type", "").startswith("image"): | |
with decoded(flow.response): | |
try: | |
s.send(flow.response.content) | |
except: | |
s.connect((TCP_IP, TCP_PORT)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment