コード例 #1
0
ファイル: test_cookies.py プロジェクト: mkagenius/mitmproxy
def test_is_expired():
    CA = cookies.CookieAttrs

    # A cookie can be expired
    # by setting the expire time in the past
    assert cookies.is_expired(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT")]))

    # or by setting Max-Age to 0
    assert cookies.is_expired(CA([("Max-Age", "0")]))

    # or both
    assert cookies.is_expired(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT"), ("Max-Age", "0")]))

    assert not cookies.is_expired(CA([("Expires", "Mon, 24-Aug-2037 00:00:00 GMT")]))
    assert not cookies.is_expired(CA([("Max-Age", "1")]))
    assert not cookies.is_expired(CA([("Expires", "Wed, 15-Jul-2037 00:00:00 GMT"), ("Max-Age", "1")]))

    assert not cookies.is_expired(CA([("Max-Age", "nan")]))
    assert not cookies.is_expired(CA([("Expires", "false")]))
コード例 #2
0
ファイル: modules.py プロジェクト: chenyi66/mitmproxy
    def handle_response(self, f):
        for name, (value, attrs) in f.response.cookies.items(multi=True):
            # FIXME: We now know that Cookie.py screws up some cookies with
            # valid RFC 822/1123 datetime specifications for expiry. Sigh.
            dom_port_path = self.ckey(attrs, f)

            if self.domain_match(f.request.host, dom_port_path[0]):
                if cookies.is_expired(attrs):
                    # Remove the cookie from jar
                    self.jar[dom_port_path].pop(name, None)

                    # If all cookies of a dom_port_path have been removed
                    # then remove it from the jar itself
                    if not self.jar[dom_port_path]:
                        self.jar.pop(dom_port_path, None)
                else:
                    b = attrs.with_insert(0, name, value)
                    self.jar[dom_port_path][name] = b
コード例 #3
0
ファイル: stickycookie.py プロジェクト: timmc/mitmproxy
    def response(self, flow):
        if self.flt:
            for name, (value, attrs) in flow.response.cookies.items(multi=True):
                # FIXME: We now know that Cookie.py screws up some cookies with
                # valid RFC 822/1123 datetime specifications for expiry. Sigh.
                dom_port_path = ckey(attrs, flow)

                if domain_match(flow.request.host, dom_port_path[0]):
                    if cookies.is_expired(attrs):
                        # Remove the cookie from jar
                        self.jar[dom_port_path].pop(name, None)

                        # If all cookies of a dom_port_path have been removed
                        # then remove it from the jar itself
                        if not self.jar[dom_port_path]:
                            self.jar.pop(dom_port_path, None)
                    else:
                        b = attrs.with_insert(0, name, value)
                        self.jar[dom_port_path][name] = b
コード例 #4
0
def test_is_expired():
    CA = cookies.CookieAttrs

    # A cookie can be expired
    # by setting the expire time in the past
    assert cookies.is_expired(
        CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT")]))

    # or by setting Max-Age to 0
    assert cookies.is_expired(CA([("Max-Age", "0")]))

    # or both
    assert cookies.is_expired(
        CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT"), ("Max-Age", "0")]))

    assert not cookies.is_expired(
        CA([("Expires", "Mon, 24-Aug-2037 00:00:00 GMT")]))
    assert not cookies.is_expired(CA([("Max-Age", "1")]))
    assert not cookies.is_expired(
        CA([("Expires", "Wed, 15-Jul-2037 00:00:00 GMT"), ("Max-Age", "1")]))

    assert not cookies.is_expired(CA([("Max-Age", "nan")]))
    assert not cookies.is_expired(CA([("Expires", "false")]))