mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
addon options: stickycookie, streambodies
This commit is contained in:
parent
704c1db1b7
commit
2aa7ac584b
@ -34,6 +34,12 @@ class StickyCookie:
|
||||
self.jar = collections.defaultdict(dict) # type: Dict[TOrigin, Dict[str, str]]
|
||||
self.flt = None # type: Optional[flowfilter.TFilter]
|
||||
|
||||
def load(self, loader):
|
||||
loader.add_option(
|
||||
"stickycookie", Optional[str], None,
|
||||
"Set sticky cookie filter. Matched against requests."
|
||||
)
|
||||
|
||||
def configure(self, updated):
|
||||
if "stickycookie" in updated:
|
||||
if ctx.options.stickycookie:
|
||||
|
@ -1,3 +1,5 @@
|
||||
import typing
|
||||
|
||||
from mitmproxy.net.http import http1
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy import ctx
|
||||
@ -8,6 +10,23 @@ class StreamBodies:
|
||||
def __init__(self):
|
||||
self.max_size = None
|
||||
|
||||
def load(self, loader):
|
||||
loader.add_option(
|
||||
"stream_large_bodies", typing.Optional[str], None,
|
||||
"""
|
||||
Stream data to the client if response body exceeds the given
|
||||
threshold. If streamed, the body will not be stored in any way.
|
||||
Understands k/m/g suffixes, i.e. 3m for 3 megabytes.
|
||||
"""
|
||||
)
|
||||
loader.add_option(
|
||||
"stream_websockets", bool, False,
|
||||
"""
|
||||
Stream WebSocket messages between client and server.
|
||||
Messages are captured and cannot be modified.
|
||||
"""
|
||||
)
|
||||
|
||||
def configure(self, updated):
|
||||
if "stream_large_bodies" in updated and ctx.options.stream_large_bodies:
|
||||
try:
|
||||
|
@ -67,10 +67,6 @@ class Options(optmanager.OptManager):
|
||||
view_filter = None # type: Optional[str]
|
||||
|
||||
# FIXME: Options that should be uncomplicated to migrate to addons
|
||||
stickyauth = None # type: Optional[str]
|
||||
stickycookie = None # type: Optional[str]
|
||||
stream_large_bodies = None # type: Optional[str]
|
||||
stream_websockets = None # type: bool
|
||||
upstream_auth = None # type: Optional[str]
|
||||
view_order = None # type: str
|
||||
view_order_reversed = None # type: bool
|
||||
@ -89,25 +85,6 @@ class Options(optmanager.OptManager):
|
||||
"showhost", bool, False,
|
||||
"Use the Host header to construct URLs for display."
|
||||
)
|
||||
self.add_option(
|
||||
"stickycookie", Optional[str], None,
|
||||
"Set sticky cookie filter. Matched against requests."
|
||||
)
|
||||
self.add_option(
|
||||
"stream_large_bodies", Optional[str], None,
|
||||
"""
|
||||
Stream data to the client if response body exceeds the given
|
||||
threshold. If streamed, the body will not be stored in any way.
|
||||
Understands k/m/g suffixes, i.e. 3m for 3 megabytes.
|
||||
"""
|
||||
)
|
||||
self.add_option(
|
||||
"stream_websockets", bool, False,
|
||||
"""
|
||||
Stream WebSocket messages between client and server.
|
||||
Messages are captured and cannot be modified.
|
||||
"""
|
||||
)
|
||||
self.add_option(
|
||||
"verbosity", str, 'info',
|
||||
"Log verbosity.",
|
||||
|
@ -15,7 +15,7 @@ def test_domain_match():
|
||||
class TestStickyCookie:
|
||||
def test_config(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
with pytest.raises(Exception, match="invalid filter"):
|
||||
tctx.configure(sc, stickycookie="~b")
|
||||
|
||||
@ -26,7 +26,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_simple(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
f = tflow.tflow(resp=True)
|
||||
f.response.headers["set-cookie"] = "foo=bar"
|
||||
@ -50,7 +50,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_response(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
c = "SSID=mooo; domain=.google.com, FOO=bar; Domain=.google.com; Path=/; " \
|
||||
@ -68,7 +68,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_response_multiple(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
# Test setting of multiple cookies
|
||||
@ -82,7 +82,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_response_weird(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
# Test setting of weird cookie keys
|
||||
@ -100,7 +100,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_response_overwrite(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
# Test overwriting of a cookie value
|
||||
@ -115,7 +115,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_response_delete(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
# Test that a cookie is be deleted
|
||||
@ -127,7 +127,7 @@ class TestStickyCookie:
|
||||
|
||||
def test_request(self):
|
||||
sc = stickycookie.StickyCookie()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sc) as tctx:
|
||||
tctx.configure(sc, stickycookie=".*")
|
||||
|
||||
f = self._response(sc, "SSID=mooo", "www.google.com")
|
||||
|
@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
def test_simple():
|
||||
sa = streambodies.StreamBodies()
|
||||
with taddons.context() as tctx:
|
||||
with taddons.context(sa) as tctx:
|
||||
with pytest.raises(exceptions.OptionsError):
|
||||
tctx.configure(sa, stream_large_bodies = "invalid")
|
||||
tctx.configure(sa, stream_large_bodies = "10")
|
||||
|
Loading…
Reference in New Issue
Block a user