mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Merge pull request #1715 from cortesi/deprecated
Remove deprecated interfaces
This commit is contained in:
commit
4b5ed2c84e
@ -2,7 +2,6 @@ from mitmproxy.net.http.request import Request
|
|||||||
from mitmproxy.net.http.response import Response
|
from mitmproxy.net.http.response import Response
|
||||||
from mitmproxy.net.http.message import Message
|
from mitmproxy.net.http.message import Message
|
||||||
from mitmproxy.net.http.headers import Headers, parse_content_type
|
from mitmproxy.net.http.headers import Headers, parse_content_type
|
||||||
from mitmproxy.net.http.message import decoded
|
|
||||||
from mitmproxy.net.http import http1, http2, status_codes, multipart
|
from mitmproxy.net.http import http1, http2, status_codes, multipart
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -10,6 +9,5 @@ __all__ = [
|
|||||||
"Response",
|
"Response",
|
||||||
"Message",
|
"Message",
|
||||||
"Headers", "parse_content_type",
|
"Headers", "parse_content_type",
|
||||||
"decoded",
|
|
||||||
"http1", "http2", "status_codes", "multipart",
|
"http1", "http2", "status_codes", "multipart",
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import re
|
import re
|
||||||
import warnings
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from mitmproxy.utils import strutils
|
from mitmproxy.utils import strutils
|
||||||
@ -269,32 +268,3 @@ class Message(serializable.Serializable):
|
|||||||
)
|
)
|
||||||
replacements += self.headers.replace(pattern, repl, flags=flags, count=count)
|
replacements += self.headers.replace(pattern, repl, flags=flags, count=count)
|
||||||
return replacements
|
return replacements
|
||||||
|
|
||||||
# Legacy
|
|
||||||
|
|
||||||
@property
|
|
||||||
def body(self): # pragma: no cover
|
|
||||||
warnings.warn(".body is deprecated, use .content instead.", DeprecationWarning)
|
|
||||||
return self.content
|
|
||||||
|
|
||||||
@body.setter
|
|
||||||
def body(self, body): # pragma: no cover
|
|
||||||
warnings.warn(".body is deprecated, use .content instead.", DeprecationWarning)
|
|
||||||
self.content = body
|
|
||||||
|
|
||||||
|
|
||||||
class decoded:
|
|
||||||
"""
|
|
||||||
Deprecated: You can now directly use :py:attr:`content`.
|
|
||||||
:py:attr:`raw_content` has the encoded content.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, message): # pragma no cover
|
|
||||||
warnings.warn("decoded() is deprecated, you can now directly use .content instead. "
|
|
||||||
".raw_content has the encoded content.", DeprecationWarning)
|
|
||||||
|
|
||||||
def __enter__(self): # pragma no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __exit__(self, type, value, tb): # pragma no cover
|
|
||||||
pass
|
|
||||||
|
@ -252,7 +252,7 @@ class HttpLayer(base.Layer):
|
|||||||
# TODO: We may have to use send_response_headers for HTTP2 here.
|
# TODO: We may have to use send_response_headers for HTTP2 here.
|
||||||
self.send_response(http.expect_continue_response)
|
self.send_response(http.expect_continue_response)
|
||||||
request.headers.pop("expect")
|
request.headers.pop("expect")
|
||||||
request.body = b"".join(self.read_request_body(request))
|
request.content = b"".join(self.read_request_body(request))
|
||||||
request.timestamp_end = time.time()
|
request.timestamp_end = time.time()
|
||||||
return request
|
return request
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr
|
|||||||
self.server_conn.h2.safe_send_body(
|
self.server_conn.h2.safe_send_body(
|
||||||
self.raise_zombie,
|
self.raise_zombie,
|
||||||
self.server_stream_id,
|
self.server_stream_id,
|
||||||
[message.body]
|
[message.content]
|
||||||
)
|
)
|
||||||
|
|
||||||
@detect_zombie_stream
|
@detect_zombie_stream
|
||||||
|
@ -190,8 +190,8 @@ class HTTP2StateProtocol:
|
|||||||
stream_id = self._next_stream_id()
|
stream_id = self._next_stream_id()
|
||||||
|
|
||||||
return list(itertools.chain(
|
return list(itertools.chain(
|
||||||
self._create_headers(headers, stream_id, end_stream=(request.body is None or len(request.body) == 0)),
|
self._create_headers(headers, stream_id, end_stream=(request.content is None or len(request.content) == 0)),
|
||||||
self._create_body(request.body, stream_id)))
|
self._create_body(request.content, stream_id)))
|
||||||
|
|
||||||
def assemble_response(self, response):
|
def assemble_response(self, response):
|
||||||
assert isinstance(response, mitmproxy.net.http.response.Response)
|
assert isinstance(response, mitmproxy.net.http.response.Response)
|
||||||
@ -207,8 +207,8 @@ class HTTP2StateProtocol:
|
|||||||
stream_id = self._next_stream_id()
|
stream_id = self._next_stream_id()
|
||||||
|
|
||||||
return list(itertools.chain(
|
return list(itertools.chain(
|
||||||
self._create_headers(headers, stream_id, end_stream=(response.body is None or len(response.body) == 0)),
|
self._create_headers(headers, stream_id, end_stream=(response.content is None or len(response.content) == 0)),
|
||||||
self._create_body(response.body, stream_id),
|
self._create_body(response.content, stream_id),
|
||||||
))
|
))
|
||||||
|
|
||||||
def perform_connection_preface(self, force=False):
|
def perform_connection_preface(self, force=False):
|
||||||
|
@ -273,7 +273,7 @@ class TestSimple(_Http2Test):
|
|||||||
assert self.master.state.flows[0].response.status_code == 200
|
assert self.master.state.flows[0].response.status_code == 200
|
||||||
assert self.master.state.flows[0].response.headers['server-foo'] == 'server-bar'
|
assert self.master.state.flows[0].response.headers['server-foo'] == 'server-bar'
|
||||||
assert self.master.state.flows[0].response.headers['föo'] == 'bär'
|
assert self.master.state.flows[0].response.headers['föo'] == 'bär'
|
||||||
assert self.master.state.flows[0].response.body == b'response body'
|
assert self.master.state.flows[0].response.content == b'response body'
|
||||||
assert self.request_body_buffer == b'request body'
|
assert self.request_body_buffer == b'request body'
|
||||||
assert response_body_buffer == b'response body'
|
assert response_body_buffer == b'response body'
|
||||||
|
|
||||||
@ -731,7 +731,7 @@ class TestPushPromise(_Http2Test):
|
|||||||
assert ended_streams == 3
|
assert ended_streams == 3
|
||||||
assert pushed_streams == 2
|
assert pushed_streams == 2
|
||||||
|
|
||||||
bodies = [flow.response.body for flow in self.master.state.flows]
|
bodies = [flow.response.content for flow in self.master.state.flows]
|
||||||
assert len(bodies) == 3
|
assert len(bodies) == 3
|
||||||
assert b'regular_stream' in bodies
|
assert b'regular_stream' in bodies
|
||||||
assert b'pushed_stream_foo' in bodies
|
assert b'pushed_stream_foo' in bodies
|
||||||
@ -783,7 +783,7 @@ class TestPushPromise(_Http2Test):
|
|||||||
client.wfile.write(h2_conn.data_to_send())
|
client.wfile.write(h2_conn.data_to_send())
|
||||||
client.wfile.flush()
|
client.wfile.flush()
|
||||||
|
|
||||||
bodies = [flow.response.body for flow in self.master.state.flows if flow.response]
|
bodies = [flow.response.content for flow in self.master.state.flows if flow.response]
|
||||||
assert len(bodies) >= 1
|
assert len(bodies) >= 1
|
||||||
assert b'regular_stream' in bodies
|
assert b'regular_stream' in bodies
|
||||||
# the other two bodies might not be transmitted before the reset
|
# the other two bodies might not be transmitted before the reset
|
||||||
@ -889,7 +889,7 @@ class TestMaxConcurrentStreams(_Http2Test):
|
|||||||
assert len(self.master.state.flows) == len(new_streams)
|
assert len(self.master.state.flows) == len(new_streams)
|
||||||
for flow in self.master.state.flows:
|
for flow in self.master.state.flows:
|
||||||
assert flow.response.status_code == 200
|
assert flow.response.status_code == 200
|
||||||
assert b"Stream-ID " in flow.response.body
|
assert b"Stream-ID " in flow.response.content
|
||||||
|
|
||||||
|
|
||||||
@requires_alpn
|
@requires_alpn
|
||||||
|
Loading…
Reference in New Issue
Block a user