From fa762e6b25a40bb317f855bba240cb1a496a29e9 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Wed, 24 Sep 2014 15:36:09 -0700 Subject: [PATCH] etcdhttp: process dir parameter in request --- etcdserver/etcdhttp/http.go | 10 +++++++++- etcdserver/etcdhttp/http_test.go | 30 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/etcdserver/etcdhttp/http.go b/etcdserver/etcdhttp/http.go index d1ed5be78..ca4750bef 100644 --- a/etcdserver/etcdhttp/http.go +++ b/etcdserver/etcdhttp/http.go @@ -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 { return emptyReq, etcdErr.NewRequestError( etcdErr.EcodeInvalidField, @@ -207,6 +207,13 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) { `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 { return emptyReq, etcdErr.NewRequestError( etcdErr.EcodeInvalidField, @@ -247,6 +254,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) { Method: r.Method, Path: p, Val: r.FormValue("value"), + Dir: dir, PrevValue: pV, PrevIndex: pIdx, PrevExist: pe, diff --git a/etcdserver/etcdhttp/http_test.go b/etcdserver/etcdhttp/http_test.go index 2fc8abb13..66f215d68 100644 --- a/etcdserver/etcdhttp/http_test.go +++ b/etcdserver/etcdhttp/http_test.go @@ -102,7 +102,7 @@ func TestBadParseRequest(t *testing.T) { mustNewForm(t, "foo", url.Values{"ttl": []string{"-1"}}), 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"}}), etcdErr.EcodeInvalidField, @@ -139,6 +139,14 @@ func TestBadParseRequest(t *testing.T) { mustNewForm(t, "foo", url.Values{"prevExist": []string{"#2"}}), 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"}}), etcdErr.EcodeInvalidField, @@ -305,6 +313,26 @@ func TestGoodParseRequest(t *testing.T) { 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 mustNewForm(