mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
code -> status_code, httpversion -> http_version
This commit is contained in:
parent
8fa01f41a6
commit
6661ad3143
@ -23,7 +23,7 @@ class Path(base.Value):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Code(base.Integer):
|
class StatusCode(base.Integer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -155,15 +155,15 @@ class Response(_HTTPMessage):
|
|||||||
actions.DisconnectAt,
|
actions.DisconnectAt,
|
||||||
actions.InjectAt,
|
actions.InjectAt,
|
||||||
)
|
)
|
||||||
logattrs = ["code", "reason", "version", "body"]
|
logattrs = ["status_code", "reason", "version", "body"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ws(self):
|
def ws(self):
|
||||||
return self.tok(WS)
|
return self.tok(WS)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code(self):
|
def status_code(self):
|
||||||
return self.tok(Code)
|
return self.tok(StatusCode)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reason(self):
|
def reason(self):
|
||||||
@ -171,15 +171,15 @@ class Response(_HTTPMessage):
|
|||||||
|
|
||||||
def preamble(self, settings):
|
def preamble(self, settings):
|
||||||
l = [self.version, " "]
|
l = [self.version, " "]
|
||||||
l.extend(self.code.values(settings))
|
l.extend(self.status_code.values(settings))
|
||||||
code = int(self.code.value)
|
status_code = int(self.status_code.value)
|
||||||
l.append(" ")
|
l.append(" ")
|
||||||
if self.reason:
|
if self.reason:
|
||||||
l.extend(self.reason.values(settings))
|
l.extend(self.reason.values(settings))
|
||||||
else:
|
else:
|
||||||
l.append(
|
l.append(
|
||||||
status_codes.RESPONSES.get(
|
status_codes.RESPONSES.get(
|
||||||
code,
|
status_code,
|
||||||
"Unknown code"
|
"Unknown code"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -192,10 +192,10 @@ class Response(_HTTPMessage):
|
|||||||
raise exceptions.RenderError(
|
raise exceptions.RenderError(
|
||||||
"No websocket key - have we seen a client handshake?"
|
"No websocket key - have we seen a client handshake?"
|
||||||
)
|
)
|
||||||
if not self.code:
|
if not self.status_code:
|
||||||
tokens.insert(
|
tokens.insert(
|
||||||
1,
|
1,
|
||||||
Code(101)
|
StatusCode(101)
|
||||||
)
|
)
|
||||||
headers = netlib.websockets.WebsocketsProtocol.server_handshake_headers(
|
headers = netlib.websockets.WebsocketsProtocol.server_handshake_headers(
|
||||||
settings.websocket_key
|
settings.websocket_key
|
||||||
@ -235,9 +235,9 @@ class Response(_HTTPMessage):
|
|||||||
pp.MatchFirst(
|
pp.MatchFirst(
|
||||||
[
|
[
|
||||||
WS.expr() + pp.Optional(
|
WS.expr() + pp.Optional(
|
||||||
base.Sep + Code.expr()
|
base.Sep + StatusCode.expr()
|
||||||
),
|
),
|
||||||
Code.expr(),
|
StatusCode.expr(),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
pp.ZeroOrMore(base.Sep + atom)
|
pp.ZeroOrMore(base.Sep + atom)
|
||||||
@ -370,7 +370,7 @@ class Request(_HTTPMessage):
|
|||||||
|
|
||||||
def make_error_response(reason, body=None):
|
def make_error_response(reason, body=None):
|
||||||
tokens = [
|
tokens = [
|
||||||
Code("800"),
|
StatusCode("800"),
|
||||||
Header(
|
Header(
|
||||||
base.TokValueLiteral("Content-Type"),
|
base.TokValueLiteral("Content-Type"),
|
||||||
base.TokValueLiteral("text/plain")
|
base.TokValueLiteral("text/plain")
|
||||||
|
@ -83,7 +83,7 @@ class _HTTP2Message(message.Message):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
class Code(base.Integer):
|
class StatusCode(base.Integer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -159,8 +159,8 @@ class Response(_HTTP2Message):
|
|||||||
self.stream_id = 2
|
self.stream_id = 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code(self):
|
def status_code(self):
|
||||||
return self.tok(Code)
|
return self.tok(StatusCode)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def expr(cls):
|
def expr(cls):
|
||||||
@ -168,7 +168,7 @@ class Response(_HTTP2Message):
|
|||||||
atom = pp.MatchFirst(parts)
|
atom = pp.MatchFirst(parts)
|
||||||
resp = pp.And(
|
resp = pp.And(
|
||||||
[
|
[
|
||||||
Code.expr(),
|
StatusCode.expr(),
|
||||||
pp.ZeroOrMore(base.Sep + atom)
|
pp.ZeroOrMore(base.Sep + atom)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -187,7 +187,7 @@ class Response(_HTTP2Message):
|
|||||||
|
|
||||||
resp = http.Response(
|
resp = http.Response(
|
||||||
(2, 0),
|
(2, 0),
|
||||||
self.code.string(),
|
self.status_code.string(),
|
||||||
'',
|
'',
|
||||||
headers,
|
headers,
|
||||||
body,
|
body,
|
||||||
@ -289,7 +289,7 @@ class Request(_HTTP2Message):
|
|||||||
|
|
||||||
def make_error_response(reason, body=None):
|
def make_error_response(reason, body=None):
|
||||||
tokens = [
|
tokens = [
|
||||||
Code("800"),
|
StatusCode("800"),
|
||||||
Body(base.TokValueLiteral("pathod error: " + (body or reason))),
|
Body(base.TokValueLiteral("pathod error: " + (body or reason))),
|
||||||
]
|
]
|
||||||
return Response(tokens)
|
return Response(tokens)
|
||||||
|
@ -134,11 +134,11 @@ class PathodHandler(tcp.BaseHandler):
|
|||||||
return None, dict(type="error", msg=s)
|
return None, dict(type="error", msg=s)
|
||||||
|
|
||||||
if req.method == 'CONNECT':
|
if req.method == 'CONNECT':
|
||||||
return self.protocol.handle_http_connect([req.host, req.port, req.httpversion], lg)
|
return self.protocol.handle_http_connect([req.host, req.port, req.http_version], lg)
|
||||||
|
|
||||||
method = req.method
|
method = req.method
|
||||||
path = req.path
|
path = req.path
|
||||||
httpversion = req.httpversion
|
http_version = req.http_version
|
||||||
headers = req.headers
|
headers = req.headers
|
||||||
body = req.body
|
body = req.body
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class PathodHandler(tcp.BaseHandler):
|
|||||||
path=path,
|
path=path,
|
||||||
method=method,
|
method=method,
|
||||||
headers=headers.fields,
|
headers=headers.fields,
|
||||||
httpversion=httpversion,
|
http_version=http_version,
|
||||||
sni=self.sni,
|
sni=self.sni,
|
||||||
remote_address=self.address(),
|
remote_address=self.address(),
|
||||||
clientcert=clientcert,
|
clientcert=clientcert,
|
||||||
|
@ -149,7 +149,7 @@ class TestResponse:
|
|||||||
|
|
||||||
def test_response(self):
|
def test_response(self):
|
||||||
r = language.parse_pathod("400:m'msg'").next()
|
r = language.parse_pathod("400:m'msg'").next()
|
||||||
assert r.code.string() == "400"
|
assert r.status_code.string() == "400"
|
||||||
assert r.reason.string() == "msg"
|
assert r.reason.string() == "msg"
|
||||||
|
|
||||||
r = language.parse_pathod("400:m'msg':b@100b").next()
|
r = language.parse_pathod("400:m'msg':b@100b").next()
|
||||||
@ -158,7 +158,7 @@ class TestResponse:
|
|||||||
assert str(r)
|
assert str(r)
|
||||||
|
|
||||||
r = language.parse_pathod("200").next()
|
r = language.parse_pathod("200").next()
|
||||||
assert r.code.string() == "200"
|
assert r.status_code.string() == "200"
|
||||||
assert not r.reason
|
assert not r.reason
|
||||||
assert "OK" in [i[:] for i in r.preamble({})]
|
assert "OK" in [i[:] for i in r.preamble({})]
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ class TestResponse:
|
|||||||
r = language.parse_pathod("ws").next()
|
r = language.parse_pathod("ws").next()
|
||||||
tutils.raises("no websocket key", r.resolve, language.Settings())
|
tutils.raises("no websocket key", r.resolve, language.Settings())
|
||||||
res = r.resolve(language.Settings(websocket_key="foo"))
|
res = r.resolve(language.Settings(websocket_key="foo"))
|
||||||
assert res.code.string() == "101"
|
assert res.status_code.string() == "101"
|
||||||
|
|
||||||
|
|
||||||
def test_ctype_shortcut():
|
def test_ctype_shortcut():
|
||||||
|
@ -187,13 +187,13 @@ class TestResponse:
|
|||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
r = parse_response('200:r:h"foo"="bar"')
|
r = parse_response('200:r:h"foo"="bar"')
|
||||||
assert r.code.string() == "200"
|
assert r.status_code.string() == "200"
|
||||||
assert len(r.headers) == 1
|
assert len(r.headers) == 1
|
||||||
assert r.headers[0].values(default_settings()) == ("foo", "bar")
|
assert r.headers[0].values(default_settings()) == ("foo", "bar")
|
||||||
assert r.body is None
|
assert r.body is None
|
||||||
|
|
||||||
r = parse_response('200:r:h"foo"="bar":bfoobar:h"bla"="fasel"')
|
r = parse_response('200:r:h"foo"="bar":bfoobar:h"bla"="fasel"')
|
||||||
assert r.code.string() == "200"
|
assert r.status_code.string() == "200"
|
||||||
assert len(r.headers) == 2
|
assert len(r.headers) == 2
|
||||||
assert r.headers[0].values(default_settings()) == ("foo", "bar")
|
assert r.headers[0].values(default_settings()) == ("foo", "bar")
|
||||||
assert r.headers[1].values(default_settings()) == ("bla", "fasel")
|
assert r.headers[1].values(default_settings()) == ("bla", "fasel")
|
||||||
|
Loading…
Reference in New Issue
Block a user