mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Change response spec format to code[:features]
Reason message is now specified as just another feature with the "m" mnemonic.
This commit is contained in:
parent
07560ffe30
commit
61f8992fbf
@ -586,7 +586,8 @@ class Reason(_Component):
|
||||
|
||||
@classmethod
|
||||
def expr(klass):
|
||||
e = Value.copy()
|
||||
e = pp.Literal("m").suppress()
|
||||
e = e + Value
|
||||
return e.setParseAction(lambda x: klass(*x))
|
||||
|
||||
def values(self, settings):
|
||||
@ -724,7 +725,8 @@ class Response(Message):
|
||||
InjectAt,
|
||||
ShortcutContentType,
|
||||
ShortcutLocation,
|
||||
Raw
|
||||
Raw,
|
||||
Reason
|
||||
)
|
||||
logattrs = ["code", "reason", "version", "body"]
|
||||
def __init__(self):
|
||||
@ -749,7 +751,6 @@ class Response(Message):
|
||||
resp = pp.And(
|
||||
[
|
||||
Code.expr(),
|
||||
pp.Optional(Reason.expr()),
|
||||
pp.ZeroOrMore(Sep + atom)
|
||||
]
|
||||
)
|
||||
|
@ -17,17 +17,10 @@
|
||||
<div class="tab-pane active" id="specifying_responses">
|
||||
<p>The general form of a response is as follows:</p>
|
||||
|
||||
<pre class="example">code[MESSAGE]:[colon-separated list of features]</pre></p>
|
||||
<pre class="example">code:[colon-separated list of features]</pre></p>
|
||||
|
||||
<table class="table table-bordered">
|
||||
<tbody >
|
||||
<tr>
|
||||
<td> h<a href="#valuespec">VALUE</a>=<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Set a header.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> b<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
@ -44,6 +37,21 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> d<a href="#offsetspec">OFFSET</a> </td>
|
||||
<td>
|
||||
Disconnect after OFFSET bytes.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> h<a href="#valuespec">VALUE</a>=<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Set a header.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td> i<a href="#offsetspec">OFFSET</a>,<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
@ -60,9 +68,10 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> d<a href="#offsetspec">OFFSET</a> </td>
|
||||
<td> m<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Disconnect after OFFSET bytes.
|
||||
HTTP Reason message. Automatically chosen according to
|
||||
the response code if not specified.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -94,13 +103,6 @@
|
||||
|
||||
<table class="table table-bordered">
|
||||
<tbody >
|
||||
<tr>
|
||||
<td> h<a href="#valuespec">VALUE</a>=<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Set a header.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> b<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
@ -118,16 +120,23 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> i<a href="#offsetspec">OFFSET</a>,<a href="#valuespec">VALUE</a> </td>
|
||||
<td> d<a href="#offsetspec">OFFSET</a> </td>
|
||||
<td>
|
||||
Inject the specified value at the offset.
|
||||
Disconnect after OFFSET bytes.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> d<a href="#offsetspec">OFFSET</a> </td>
|
||||
<td> h<a href="#valuespec">VALUE</a>=<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Disconnect after OFFSET bytes.
|
||||
Set a header.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td> i<a href="#offsetspec">OFFSET</a>,<a href="#valuespec">VALUE</a> </td>
|
||||
<td>
|
||||
Inject the specified value at the offset.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
name="spec"
|
||||
class="input-medium search-query"
|
||||
value="{{spec}}"
|
||||
placeholder="code[msg]:[features]"
|
||||
placeholder="code:[features]"
|
||||
>
|
||||
<a id="gopublic" class="btn">go</a>
|
||||
</p>
|
||||
|
@ -5,7 +5,7 @@
|
||||
name="spec"
|
||||
class="input-medium search-query"
|
||||
value="{{spec}}"
|
||||
placeholder="code[msg]:[features]"
|
||||
placeholder="code:[features]"
|
||||
>
|
||||
<input type="submit" class="btn" value="preview">
|
||||
{% if not nocraft %}
|
||||
|
@ -498,11 +498,11 @@ class TestResponse:
|
||||
assert r.code.string() == "202"
|
||||
|
||||
def test_response(self):
|
||||
r = language.parse_response({}, "400'msg'")
|
||||
r = language.parse_response({}, "400:m'msg'")
|
||||
assert r.code.string() == "400"
|
||||
assert r.reason.string() == "msg"
|
||||
|
||||
r = language.parse_response({}, "400'msg':b@100b")
|
||||
r = language.parse_response({}, "400:m'msg':b@100b")
|
||||
assert r.reason.string() == "msg"
|
||||
assert r.body.values({})
|
||||
assert str(r)
|
||||
@ -514,7 +514,7 @@ class TestResponse:
|
||||
|
||||
def test_render(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400'msg'")
|
||||
r = language.parse_response({}, "400:m'msg'")
|
||||
assert r.serve(s, {})
|
||||
|
||||
def test_raw(self):
|
||||
@ -537,9 +537,9 @@ class TestResponse:
|
||||
s = cStringIO.StringIO()
|
||||
x.serve(s, {})
|
||||
assert x.length({}, None) == len(s.getvalue())
|
||||
testlen(language.parse_response({}, "400'msg'"))
|
||||
testlen(language.parse_response({}, "400'msg':h'foo'='bar'"))
|
||||
testlen(language.parse_response({}, "400'msg':h'foo'='bar':b@100b"))
|
||||
testlen(language.parse_response({}, "400:m'msg'"))
|
||||
testlen(language.parse_response({}, "400:m'msg':h'foo'='bar'"))
|
||||
testlen(language.parse_response({}, "400:m'msg':h'foo'='bar':b@100b"))
|
||||
|
||||
def test_maximum_length(self):
|
||||
def testlen(x, actions):
|
||||
@ -548,7 +548,7 @@ class TestResponse:
|
||||
x.serve(s, {})
|
||||
assert m >= len(s.getvalue())
|
||||
|
||||
r = language.parse_response({}, "400'msg':b@100")
|
||||
r = language.parse_response({}, "400:m'msg':b@100")
|
||||
|
||||
actions = [
|
||||
language.DisconnectAt(0)
|
||||
|
@ -40,7 +40,6 @@ class TestTimeout(tutils.DaemonTests):
|
||||
# FIXME: Add float values to spec language, reduce test timeout to
|
||||
# increase test performance
|
||||
assert self.get("200:p1,1").status_code == 200
|
||||
print self.d.last_log()
|
||||
assert self.d.last_log()["type"] == "timeout"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user