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