All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.__pycache__.proxy.cpython-37.pyc Maven / Gradle / Ivy

Go to download

A bridge between Python's mitmproxy and Java programs. Built on top of mitmproxy-node

There is a newer version: 2.0.2
Show newest version
B

?د\?"?@s?dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
dd?Zdd?Zd	d
?ZGdd?d?Ze?gZdS)
zd
Interception proxy using mitmproxy (https://mitmproxy.org).
Communicates to NodeJS via websockets.
?N)?ctx)?httpcCst|dd?t|dd?gS)z<
    Converts a tuple of strings into a tuple of bytes.
    r?utf8?)?bytes)Zheader_entry?r?scripts/proxy.py?convert_headers_to_bytessr	cCs|dkrt?S|SdS)zG
    Converts a HTTP request/response body into a list of numbers.
    N)r)?bodyrrr?convert_body_to_bytessrcCs4d|kr0|d??}d|kp.d|kp.|??dkSdS)Nzcontent-type?application?text?T)?lower?strip)?headers?ctrrr?is_text_response#src@s`eZdZdZdd?Zdd?Zdd?Zdd	?Zd
d?Zdd
?Z	dd?Z
dd?Zdd?Zdd?Z
dS)?WebSocketAdapterzo
    Relays HTTP/HTTPS requests to a websocket server.
    Enables using MITMProxy from outside of Python.
    cCst??|_|j?|???dS)zz
        Main function of the websocket thread. Runs the websocket event loop
        until MITMProxy shuts down.
        N)?asyncio?new_event_loopZworker_event_loop?run_until_complete?websocket_loop)?selfrrr?websocket_thread0s
z!WebSocketAdapter.websocket_threadcCs6t??|_tg?|_d|_d|_tj|jd??	?dS)NF)?target)
?queue?Queue?	frozenset?intercept_paths?only_intercept_text_files?finished?	threading?Threadr?start)rrrr?__init__8s


zWebSocketAdapter.__init__cCs&|?dtdd?|jdtddd?dS)N?	interceptrz?
            A list of HTTP paths, delimited by a comma, to intercept and pass to Node without hitting the server.
            E.g.: /foo,/bar
            ?onlyInterceptTextFilesFzVIf true, the plugin only intercepts text files and passes through other types of files)?name?typespec?default?help)?
add_option?str?bool)r?loaderrrr?load@szWebSocketAdapter.loadcCs2d|krttjj?d??|_d|kr.tjj|_dS)Nr&?,r')rr?optionsr&?splitrr'r )rZupdatesrrr?	configurePs

zWebSocketAdapter.configurec
	Cs?tt?|?d?}t|?}t|?}t|?}t?dt|?dt|?dt|?d||||||?}t??|dd?}	|	d?	?|j
?|	?|	d??|	d}
|
dkr?dSt|
?}t?
dt|d	?d|
?}t?|d
d|d??|d
|dd?fS)z?
        Sends the given message on the WebSocket connection,
        and awaits a response. Metadata is a JSONable object,
        and data is bytes.
        rzr`?	mitmproxyrrr	rrr?addonsrrrr?s$	V




© 2015 - 2024 Weber Informatics LLC | Privacy Policy