mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdhttp: process dir parameter in request
This commit is contained in:
parent
98561f6b5d
commit
fa762e6b25
@ -188,7 +188,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rec, sort, wait, stream bool
|
var rec, sort, wait, dir, stream bool
|
||||||
if rec, err = getBool(r.Form, "recursive"); err != nil {
|
if rec, err = getBool(r.Form, "recursive"); err != nil {
|
||||||
return emptyReq, etcdErr.NewRequestError(
|
return emptyReq, etcdErr.NewRequestError(
|
||||||
etcdErr.EcodeInvalidField,
|
etcdErr.EcodeInvalidField,
|
||||||
@ -207,6 +207,13 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
|
|||||||
`invalid value for "wait"`,
|
`invalid value for "wait"`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// TODO(jonboulle): define what parameters dir is/isn't compatible with?
|
||||||
|
if dir, err = getBool(r.Form, "dir"); err != nil {
|
||||||
|
return emptyReq, etcdErr.NewRequestError(
|
||||||
|
etcdErr.EcodeInvalidField,
|
||||||
|
`invalid value for "dir"`,
|
||||||
|
)
|
||||||
|
}
|
||||||
if stream, err = getBool(r.Form, "stream"); err != nil {
|
if stream, err = getBool(r.Form, "stream"); err != nil {
|
||||||
return emptyReq, etcdErr.NewRequestError(
|
return emptyReq, etcdErr.NewRequestError(
|
||||||
etcdErr.EcodeInvalidField,
|
etcdErr.EcodeInvalidField,
|
||||||
@ -247,6 +254,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
|
|||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
Path: p,
|
Path: p,
|
||||||
Val: r.FormValue("value"),
|
Val: r.FormValue("value"),
|
||||||
|
Dir: dir,
|
||||||
PrevValue: pV,
|
PrevValue: pV,
|
||||||
PrevIndex: pIdx,
|
PrevIndex: pIdx,
|
||||||
PrevExist: pe,
|
PrevExist: pe,
|
||||||
|
@ -102,7 +102,7 @@ func TestBadParseRequest(t *testing.T) {
|
|||||||
mustNewForm(t, "foo", url.Values{"ttl": []string{"-1"}}),
|
mustNewForm(t, "foo", url.Values{"ttl": []string{"-1"}}),
|
||||||
etcdErr.EcodeTTLNaN,
|
etcdErr.EcodeTTLNaN,
|
||||||
},
|
},
|
||||||
// bad values for recursive, sorted, wait, prevExist, stream
|
// bad values for recursive, sorted, wait, prevExist, dir, stream
|
||||||
{
|
{
|
||||||
mustNewForm(t, "foo", url.Values{"recursive": []string{"hahaha"}}),
|
mustNewForm(t, "foo", url.Values{"recursive": []string{"hahaha"}}),
|
||||||
etcdErr.EcodeInvalidField,
|
etcdErr.EcodeInvalidField,
|
||||||
@ -139,6 +139,14 @@ func TestBadParseRequest(t *testing.T) {
|
|||||||
mustNewForm(t, "foo", url.Values{"prevExist": []string{"#2"}}),
|
mustNewForm(t, "foo", url.Values{"prevExist": []string{"#2"}}),
|
||||||
etcdErr.EcodeInvalidField,
|
etcdErr.EcodeInvalidField,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
mustNewForm(t, "foo", url.Values{"dir": []string{"no"}}),
|
||||||
|
etcdErr.EcodeInvalidField,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mustNewForm(t, "foo", url.Values{"dir": []string{"file"}}),
|
||||||
|
etcdErr.EcodeInvalidField,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
mustNewForm(t, "foo", url.Values{"stream": []string{"zzz"}}),
|
mustNewForm(t, "foo", url.Values{"stream": []string{"zzz"}}),
|
||||||
etcdErr.EcodeInvalidField,
|
etcdErr.EcodeInvalidField,
|
||||||
@ -305,6 +313,26 @@ func TestGoodParseRequest(t *testing.T) {
|
|||||||
Expiration: 0,
|
Expiration: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// dir specified
|
||||||
|
mustNewRequest(t, "foo?dir=true"),
|
||||||
|
etcdserverpb.Request{
|
||||||
|
Id: 1234,
|
||||||
|
Method: "GET",
|
||||||
|
Dir: true,
|
||||||
|
Path: "/foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// dir specified negatively
|
||||||
|
mustNewRequest(t, "foo?dir=false"),
|
||||||
|
etcdserverpb.Request{
|
||||||
|
Id: 1234,
|
||||||
|
Method: "GET",
|
||||||
|
Dir: false,
|
||||||
|
Path: "/foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// prevExist should be non-null if specified
|
// prevExist should be non-null if specified
|
||||||
mustNewForm(
|
mustNewForm(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user