diff --git a/examples/har_extractor.py b/examples/har_extractor.py index f16f1909b..4e905438e 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -128,7 +128,7 @@ def response(context, flow): request_query_string = [{"name": k, "value": v} for k, v in flow.request.get_query()] - request_http_version = flow.request.httpversion + request_http_version = flow.request.http_version # Cookies are shaped as tuples by MITMProxy. request_cookies = [{"name": k.strip(), "value": v[0]} for k, v in (flow.request.get_cookies() or {}).iteritems()] @@ -136,8 +136,7 @@ def response(context, flow): request_headers_size = len(str(flow.request.headers)) request_body_size = len(flow.request.content) - response_http_version = ".".join( - [str(v) for v in flow.response.httpversion]) + response_http_version = flow.response.http_version # Cookies are shaped as tuples by MITMProxy. response_cookies = [{"name": k.strip(), "value": v[0]} for k, v in (flow.response.get_cookies() or {}).iteritems()] @@ -165,7 +164,7 @@ def response(context, flow): "bodySize": request_body_size, }, "response": { - "status": flow.response.code, + "status": flow.response.status_code, "statusText": flow.response.msg, "httpVersion": response_http_version, "cookies": response_cookies, diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 13374b251..4a2310c91 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -393,7 +393,7 @@ def format_flow(f, focus, extended=False, hostheader=False, padding=2, req_url = f.request.pretty_url(hostheader=hostheader), err_msg = f.error.msg if f.error else None, - resp_code = f.response.code if f.response else None, + resp_code = f.response.status_code if f.response else None, marked = marked, ) @@ -410,7 +410,7 @@ def format_flow(f, focus, extended=False, hostheader=False, padding=2, roundtrip = utils.pretty_duration(duration) d.update(dict( - resp_code = f.response.code, + resp_code = f.response.status_code, resp_is_replay = f.response.is_replay, resp_clen = contentdesc, roundtrip = roundtrip, diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 8220c1e7c..a95f23a39 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -298,7 +298,7 @@ class FlowView(tabs.Tabs): def set_resp_code(self, code): response = self.flow.response try: - response.code = int(code) + response.status_code = int(code) except ValueError: return None import BaseHTTPServer @@ -357,7 +357,7 @@ class FlowView(tabs.Tabs): else: if not self.flow.response: self.flow.response = HTTPResponse( - self.flow.request.httpversion, + self.flow.request.http_version, 200, "OK", Headers(), "" ) self.flow.response.reply = controller.DummyReply() @@ -447,7 +447,7 @@ class FlowView(tabs.Tabs): elif part == "o": signals.status_prompt.send( prompt = "Code", - text = str(message.code), + text = str(message.status_code), callback = self.set_resp_code ) elif part == "m": diff --git a/libmproxy/filt.py b/libmproxy/filt.py index 7cd0f4dfb..acbf4ef9d 100644 --- a/libmproxy/filt.py +++ b/libmproxy/filt.py @@ -270,7 +270,7 @@ class FCode(_Int): help = "HTTP response code" def __call__(self, f): - if f.response and f.response.code == self.num: + if f.response and f.response.status_code == self.num: return True diff --git a/libmproxy/models/http.py b/libmproxy/models/http.py index 0769d2d09..7e46c8345 100644 --- a/libmproxy/models/http.py +++ b/libmproxy/models/http.py @@ -14,7 +14,7 @@ from .flow import Flow class MessageMixin(stateobject.StateObject): _stateobject_attributes = dict( - httpversion=bytes, + http_version=bytes, headers=Headers, body=bytes, timestamp_start=float, @@ -119,7 +119,7 @@ class HTTPRequest(MessageMixin, Request): path: Path portion of the URL (not present in authority-form) - httpversion: HTTP version, e.g. "HTTP/1.1" + http_version: HTTP version, e.g. "HTTP/1.1" headers: Headers object @@ -152,7 +152,7 @@ class HTTPRequest(MessageMixin, Request): host, port, path, - httpversion, + http_version, headers, body, timestamp_start=None, @@ -167,7 +167,7 @@ class HTTPRequest(MessageMixin, Request): host, port, path, - httpversion, + http_version, headers, body, timestamp_start, @@ -230,7 +230,7 @@ class HTTPRequest(MessageMixin, Request): host=request.host, port=request.port, path=request.path, - httpversion=request.httpversion, + http_version=request.http_version, headers=request.headers, body=request.body, timestamp_start=request.timestamp_start, @@ -266,7 +266,7 @@ class HTTPResponse(MessageMixin, Response): Exposes the following attributes: - httpversion: HTTP version, e.g. "HTTP/1.1" + http_version: HTTP version, e.g. "HTTP/1.1" status_code: HTTP response status code @@ -285,7 +285,7 @@ class HTTPResponse(MessageMixin, Response): def __init__( self, - httpversion, + http_version, status_code, msg, headers, @@ -295,7 +295,7 @@ class HTTPResponse(MessageMixin, Response): ): Response.__init__( self, - httpversion, + http_version, status_code, msg, headers, @@ -333,7 +333,7 @@ class HTTPResponse(MessageMixin, Response): @classmethod def wrap(self, response): resp = HTTPResponse( - httpversion=response.httpversion, + http_version=response.http_version, status_code=response.status_code, msg=response.msg, headers=response.headers, @@ -547,13 +547,13 @@ def make_connect_request(address): ) -def make_connect_response(httpversion): +def make_connect_response(http_version): headers = Headers( Content_Length="0", Proxy_Agent=version.NAMEVERSION ) return HTTPResponse( - httpversion, + http_version, 200, "Connection established", headers, diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 53609f264..a1b2605fa 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -102,16 +102,16 @@ class Http1Layer(_StreamingHttpLayer): def check_close_connection(self, flow): request_close = http1.connection_close( - flow.request.httpversion, + flow.request.http_version, flow.request.headers ) response_close = http1.connection_close( - flow.response.httpversion, + flow.response.http_version, flow.response.headers ) read_until_eof = http1.expected_http_body_size(flow.request, flow.response) == -1 close_connection = request_close or response_close or read_until_eof - if flow.request.form_in == "authority" and flow.response.code == 200: + if flow.request.form_in == "authority" and flow.response.status_code == 200: # Workaround for https://github.com/mitmproxy/mitmproxy/issues/313: # Charles Proxy sends a CONNECT response with HTTP/1.0 # and no Content-Length header @@ -258,7 +258,7 @@ class UpstreamConnectLayer(Layer): def _send_connect_request(self): self.send_request(self.connect_request) resp = self.read_response(self.connect_request) - if resp.code != 200: + if resp.status_code != 200: raise ProtocolException("Reconnect: Upstream server refuses CONNECT request") def connect(self): @@ -345,7 +345,7 @@ class HttpLayer(Layer): return # Upstream Proxy Mode: Handle CONNECT - if flow.request.form_in == "authority" and flow.response.code == 200: + if flow.request.form_in == "authority" and flow.response.status_code == 200: self.handle_upstream_mode_connect(flow.request.copy()) return @@ -377,7 +377,7 @@ class HttpLayer(Layer): def handle_regular_mode_connect(self, request): self.set_server((request.host, request.port)) - self.send_response(make_connect_response(request.httpversion)) + self.send_response(make_connect_response(request.http_version)) layer = self.ctx.next_layer(self) layer() diff --git a/libmproxy/protocol/http_replay.py b/libmproxy/protocol/http_replay.py index 9e2a97350..00b0b82b8 100644 --- a/libmproxy/protocol/http_replay.py +++ b/libmproxy/protocol/http_replay.py @@ -56,7 +56,7 @@ class RequestReplayThread(threading.Thread): connect_request, body_size_limit=self.config.body_size_limit ) - if resp.code != 200: + if resp.status_code != 200: raise ReplayException("Upstream server refuses CONNECT request") server.establish_ssl( self.config.clientcerts, diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 8eee6dce4..5c80584dc 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -128,7 +128,7 @@ class FlowHandler(RequestHandler): if a == "request": request = flow.request for k, v in b.iteritems(): - if k in ["method", "scheme", "host", "path", "httpversion"]: + if k in ["method", "scheme", "host", "path", "http_version"]: setattr(request, k, str(v)) elif k == "port": request.port = int(v) @@ -143,9 +143,9 @@ class FlowHandler(RequestHandler): if k == "msg": response.msg = str(v) elif k == "code": - response.code = int(v) - elif k == "httpversion": - response.httpversion = str(v) + response.status_code = int(v) + elif k == "http_version": + response.http_version = str(v) elif k == "headers": response.headers.load_state(v) else: diff --git a/libmproxy/web/static/app.js b/libmproxy/web/static/app.js index b97671534..edcc95ba5 100644 --- a/libmproxy/web/static/app.js +++ b/libmproxy/web/static/app.js @@ -2098,7 +2098,7 @@ var RequestLine = React.createClass({displayName: "RequestLine", render: function () { var flow = this.props.flow; var url = flowutils.RequestUtils.pretty_url(flow.request); - var httpver = "HTTP/" + flow.request.httpversion.join("."); + var httpver = "HTTP/" + flow.request.http_version.join("."); return React.createElement("div", {className: "first-line request-line"}, React.createElement(ValueEditor, { @@ -2144,7 +2144,7 @@ var RequestLine = React.createClass({displayName: "RequestLine", var ver = flowutils.parseHttpVersion(nextVer); actions.FlowActions.update( this.props.flow, - {request: {httpversion: ver}} + {request: {http_version: ver}} ); } }); @@ -2152,7 +2152,7 @@ var RequestLine = React.createClass({displayName: "RequestLine", var ResponseLine = React.createClass({displayName: "ResponseLine", render: function () { var flow = this.props.flow; - var httpver = "HTTP/" + flow.response.httpversion.join("."); + var httpver = "HTTP/" + flow.response.http_version.join("."); return React.createElement("div", {className: "first-line response-line"}, React.createElement(ValueEditor, { ref: "httpVersion", @@ -5734,4 +5734,4 @@ module.exports = { },{"./actions.js":2,"jquery":"jquery","lodash":"lodash","react":"react"}]},{},[3]) -//# sourceMappingURL=app.js.map \ No newline at end of file +//# sourceMappingURL=app.js.map diff --git a/test/test_dump.py b/test/test_dump.py index 9d177ea08..56d3edd27 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -40,13 +40,13 @@ def test_strfuncs(): flow.client_conn.address.host = "foo" flow.response = netlib.tutils.tresp(body=CONTENT_MISSING) flow.response.is_replay = True - flow.response.code = 300 + flow.response.status_code = 300 m.echo_flow(flow) flow = tutils.tflow(resp=netlib.tutils.tresp(body="{")) flow.response.headers["content-type"] = "application/json" - flow.response.code = 400 + flow.response.status_code = 400 m.echo_flow(flow) diff --git a/test/test_flow.py b/test/test_flow.py index f73187c1e..b54b7508c 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -678,11 +678,11 @@ class TestSerialize: w = flow.FilteredFlowWriter(sio, fl) f = tutils.tflow(resp=True) - f.response.code = 200 + f.response.status_code = 200 w.add(f) f = tutils.tflow(resp=True) - f.response.code = 201 + f.response.status_code = 201 w.add(f) sio.seek(0) diff --git a/test/test_server.py b/test/test_server.py index 63357563c..d1fef6ff3 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -49,18 +49,18 @@ class CommonMixin: else: assert len(self.master.state.view) == 1 l = self.master.state.view[-1] - assert l.response.code == 304 + assert l.response.status_code == 304 l.request.path = "/p/305" self.wait_until_not_live(l) rt = self.master.replay_request(l, block=True) - assert l.response.code == 305 + assert l.response.status_code == 305 # Disconnect error l.request.path = "/p/305:d0" rt = self.master.replay_request(l, block=True) assert not rt if isinstance(self, tservers.HTTPUpstreamProxTest): - assert l.response.code == 502 + assert l.response.status_code == 502 else: assert l.error @@ -72,7 +72,7 @@ class CommonMixin: rt = self.master.replay_request(l, block=True) assert not rt if isinstance(self, tservers.HTTPUpstreamProxTest): - assert l.response.code == 502 + assert l.response.status_code == 502 else: assert l.error @@ -85,7 +85,7 @@ class CommonMixin: l = self.master.state.view[-1] assert l.client_conn.address assert "host" in l.request.headers - assert l.response.code == 304 + assert l.response.status_code == 304 def test_invalid_http(self): t = tcp.TCPClient(("127.0.0.1", self.proxy.port)) @@ -499,7 +499,7 @@ class TestProxy(tservers.HTTPProxTest): f = self.master.state.view[0] assert f.client_conn.address assert "host" in f.request.headers - assert f.response.code == 304 + assert f.response.status_code == 304 def test_response_timestamps(self): # test that we notice at least 1 sec delay between timestamps @@ -526,7 +526,7 @@ class TestProxy(tservers.HTTPProxTest): request, response = self.master.state.view[ 0].request, self.master.state.view[0].response - assert response.code == 304 # sanity test for our low level request + assert response.status_code == 304 # sanity test for our low level request # time.sleep might be a little bit shorter than a second, # we observed up to 0.93s on appveyor. assert 0.8 < (request.timestamp_end - request.timestamp_start) < 1.2 @@ -892,7 +892,7 @@ class TestUpstreamProxySSL( """ def handle_request(f): - f.request.httpversion = b"HTTP/1.1" + f.request.http_version = b"HTTP/1.1" del f.request.headers["Content-Length"] f.reply() diff --git a/web/src/js/components/flowtable-columns.js b/web/src/js/components/flowtable-columns.js index b3b47910f..74d962167 100644 --- a/web/src/js/components/flowtable-columns.js +++ b/web/src/js/components/flowtable-columns.js @@ -44,9 +44,9 @@ var IconColumn = React.createClass({ var contentType = ResponseUtils.getContentType(flow.response); //TODO: We should assign a type to the flow somewhere else. - if (flow.response.code === 304) { + if (flow.response.status_code === 304) { icon = "resource-icon-not-modified"; - } else if (300 <= flow.response.code && flow.response.code < 400) { + } else if (300 <= flow.response.status_code && flow.response.status_code < 400) { icon = "resource-icon-redirect"; } else if (contentType && contentType.indexOf("image") >= 0) { icon = "resource-icon-image"; @@ -118,14 +118,14 @@ var StatusColumn = React.createClass({ } }), sortKeyFun: function(flow){ - return flow.response ? flow.response.code : undefined; + return flow.response ? flow.response.status_code : undefined; } }, render: function () { var flow = this.props.flow; var status; if (flow.response) { - status = flow.response.code; + status = flow.response.status_code; } else { status = null; } @@ -198,4 +198,4 @@ var all_columns = [ TimeColumn ]; -module.exports = all_columns; \ No newline at end of file +module.exports = all_columns; diff --git a/web/src/js/components/flowview/messages.js b/web/src/js/components/flowview/messages.js index 8879e753c..7ac95d850 100644 --- a/web/src/js/components/flowview/messages.js +++ b/web/src/js/components/flowview/messages.js @@ -121,7 +121,7 @@ var RequestLine = React.createClass({ render: function () { var flow = this.props.flow; var url = flowutils.RequestUtils.pretty_url(flow.request); - var httpver = flow.request.httpversion; + var httpver = flow.request.http_version; return
@@ -205,7 +205,7 @@ var ResponseLine = React.createClass({ var ver = flowutils.parseHttpVersion(nextVer); actions.FlowActions.update( this.props.flow, - {response: {httpversion: ver}} + {response: {http_version: ver}} ); }, onMsgChange: function (nextMsg) { @@ -279,7 +279,7 @@ var Response = React.createClass({ edit: function (k) { switch (k) { case "c": - this.refs.responseLine.refs.code.focus(); + this.refs.responseLine.refs.status_code.focus(); break; case "m": this.refs.responseLine.refs.msg.focus(); diff --git a/web/src/js/filt/filt.js b/web/src/js/filt/filt.js index 78d6a67cb..02a04c66e 100644 --- a/web/src/js/filt/filt.js +++ b/web/src/js/filt/filt.js @@ -1654,7 +1654,7 @@ module.exports = (function() { assetFilter.desc = "is asset"; function responseCode(code){ function responseCodeFilter(flow){ - return flow.response && flow.response.code === code; + return flow.response && flow.response.status_code === code; } responseCodeFilter.desc = "resp. code is " + code; return responseCodeFilter; @@ -1771,4 +1771,4 @@ module.exports = (function() { SyntaxError: SyntaxError, parse: parse }; -})(); \ No newline at end of file +})(); diff --git a/web/src/js/filt/filt.peg b/web/src/js/filt/filt.peg index b4763ccf2..6f9bdac63 100644 --- a/web/src/js/filt/filt.peg +++ b/web/src/js/filt/filt.peg @@ -64,7 +64,7 @@ function assetFilter(flow) { assetFilter.desc = "is asset"; function responseCode(code){ function responseCodeFilter(flow){ - return flow.response && flow.response.code === code; + return flow.response && flow.response.status_code === code; } responseCodeFilter.desc = "resp. code is " + code; return responseCodeFilter; @@ -246,4 +246,4 @@ EscapeSequence = ['"\\] / "n" { return "\n"; } / "r" { return "\r"; } - / "t" { return "\t"; } \ No newline at end of file + / "t" { return "\t"; }