aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/builtins/__init__.py2
-rw-r--r--mitmproxy/builtins/anticache.py13
-rw-r--r--mitmproxy/console/options.py8
-rw-r--r--mitmproxy/console/statusbar.py2
-rw-r--r--mitmproxy/dump.py2
-rw-r--r--mitmproxy/flow/master.py4
-rw-r--r--test/mitmproxy/builtins/test_anticache.py23
-rw-r--r--test/mitmproxy/test_flow.py10
8 files changed, 43 insertions, 21 deletions
diff --git a/mitmproxy/builtins/__init__.py b/mitmproxy/builtins/__init__.py
index 867ebb22..b5419378 100644
--- a/mitmproxy/builtins/__init__.py
+++ b/mitmproxy/builtins/__init__.py
@@ -1,11 +1,13 @@
from __future__ import absolute_import, print_function, division
+from mitmproxy.builtins import anticache
from mitmproxy.builtins import anticomp
from mitmproxy.builtins import stickyauth
def default_addons():
return [
+ anticache.AntiCache(),
anticomp.AntiComp(),
stickyauth.StickyAuth(),
]
diff --git a/mitmproxy/builtins/anticache.py b/mitmproxy/builtins/anticache.py
new file mode 100644
index 00000000..f208e2fb
--- /dev/null
+++ b/mitmproxy/builtins/anticache.py
@@ -0,0 +1,13 @@
+from __future__ import absolute_import, print_function, division
+
+
+class AntiCache:
+ def __init__(self):
+ self.enabled = False
+
+ def configure(self, options):
+ self.enabled = options.anticache
+
+ def request(self, flow):
+ if self.enabled:
+ flow.request.anticache()
diff --git a/mitmproxy/console/options.py b/mitmproxy/console/options.py
index f6342814..c76a058f 100644
--- a/mitmproxy/console/options.py
+++ b/mitmproxy/console/options.py
@@ -96,7 +96,7 @@ class Options(urwid.WidgetWrap):
select.Option(
"Anti-Cache",
"a",
- lambda: master.anticache,
+ lambda: master.options.anticache,
self.toggle_anticache
),
select.Option(
@@ -152,7 +152,6 @@ class Options(urwid.WidgetWrap):
return super(self.__class__, self).keypress(size, key)
def clearall(self):
- self.master.anticache = False
self.master.killextra = False
self.master.showhost = False
self.master.refresh_server_playback = True
@@ -164,8 +163,9 @@ class Options(urwid.WidgetWrap):
self.master.scripts = []
self.master.set_stickycookie(None)
- self.master.options.stickyauth = None
+ self.master.options.anticache = False
self.master.options.anticomp = False
+ self.master.options.stickyauth = None
self.master.state.default_body_view = contentviews.get("Auto")
@@ -176,7 +176,7 @@ class Options(urwid.WidgetWrap):
)
def toggle_anticache(self):
- self.master.anticache = not self.master.anticache
+ self.master.options.anticache = not self.master.options.anticache
def toggle_anticomp(self):
self.master.options.anticomp = not self.master.options.anticomp
diff --git a/mitmproxy/console/statusbar.py b/mitmproxy/console/statusbar.py
index d0a24018..1357d7ca 100644
--- a/mitmproxy/console/statusbar.py
+++ b/mitmproxy/console/statusbar.py
@@ -187,7 +187,7 @@ class StatusBar(urwid.WidgetWrap):
r.append(":%s]" % self.master.state.default_body_view.name)
opts = []
- if self.master.anticache:
+ if self.master.options.anticache:
opts.append("anticache")
if self.master.options.anticomp:
opts.append("anticomp")
diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py
index f69e3777..b953d131 100644
--- a/mitmproxy/dump.py
+++ b/mitmproxy/dump.py
@@ -63,8 +63,6 @@ class DumpMaster(flow.FlowMaster):
self.addons.add(*builtins.default_addons())
self.outfile = outfile
self.o = options
- self.anticache = options.anticache
- self.anticomp = options.anticomp
self.showhost = options.showhost
self.replay_ignore_params = options.replay_ignore_params
self.replay_ignore_content = options.replay_ignore_content
diff --git a/mitmproxy/flow/master.py b/mitmproxy/flow/master.py
index e469c499..06e1b460 100644
--- a/mitmproxy/flow/master.py
+++ b/mitmproxy/flow/master.py
@@ -42,7 +42,6 @@ class FlowMaster(controller.Master):
self.stickycookie_state = None # type: Optional[modules.StickyCookieState]
self.stickycookie_txt = None
- self.anticache = False
self.stream_large_bodies = None # type: Optional[modules.StreamLargeBodies]
self.refresh_server_playback = False
self.replacehooks = modules.ReplaceHooks()
@@ -313,9 +312,6 @@ class FlowMaster(controller.Master):
if self.stickycookie_state:
self.stickycookie_state.handle_request(f)
- if self.anticache:
- f.request.anticache()
-
if self.server_playback:
pb = self.do_server_playback(f)
if not pb and self.kill_nonreplay:
diff --git a/test/mitmproxy/builtins/test_anticache.py b/test/mitmproxy/builtins/test_anticache.py
new file mode 100644
index 00000000..5a00af03
--- /dev/null
+++ b/test/mitmproxy/builtins/test_anticache.py
@@ -0,0 +1,23 @@
+from .. import tutils, mastertest
+from mitmproxy.builtins import anticache
+from mitmproxy.flow import master
+from mitmproxy.flow import state
+from mitmproxy import options
+
+
+class TestAntiCache(mastertest.MasterTest):
+ def test_simple(self):
+ s = state.State()
+ m = master.FlowMaster(options.Options(anticache = True), None, s)
+ sa = anticache.AntiCache()
+ m.addons.add(sa)
+
+ f = tutils.tflow(resp=True)
+ self.invoke(m, "request", f)
+
+ f = tutils.tflow(resp=True)
+ f.request.headers["if-modified-since"] = "test"
+ f.request.headers["if-none-match"] = "test"
+ self.invoke(m, "request", f)
+ assert "if-modified-since" not in f.request.headers
+ assert "if-none-match" not in f.request.headers
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index a6a3038c..585dbf93 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -855,7 +855,6 @@ class TestFlowMaster:
def test_all(self):
s = flow.State()
fm = flow.FlowMaster(None, None, s)
- fm.anticache = True
f = tutils.tflow(req=None)
fm.clientconnect(f.client_conn)
f.request = HTTPRequest.wrap(netlib.tutils.treq())
@@ -1053,15 +1052,6 @@ class TestRequest:
assert r.url == "https://address:22/path"
assert r.pretty_url == "https://foo.com:22/path"
- def test_anticache(self):
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.headers = Headers()
- r.headers["if-modified-since"] = "test"
- r.headers["if-none-match"] = "test"
- r.anticache()
- assert "if-modified-since" not in r.headers
- assert "if-none-match" not in r.headers
-
def test_replace(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.path = "path/foo"
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810