diff --git a/go.mod b/go.mod index 3f215a69d..b5b909cf4 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( github.com/golang/mock v1.3.1 github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd // indirect github.com/gorilla/mux v1.5.0 + github.com/gorilla/schema v1.1.0 github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/magiconair/properties v1.8.1 // indirect github.com/mailru/easyjson v0.0.0-20170902151237-2a92e673c9a6 // indirect diff --git a/go.sum b/go.sum index f0ca89e16..90e8ccce5 100644 --- a/go.sum +++ b/go.sum @@ -73,6 +73,8 @@ github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd h1:bB2XEQHhNsTTpqN github.com/gorilla/context v0.0.0-20181012153548-51ce91d2eadd/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.5.0 h1:mq8bRov+5x+pZNR/uAHyUEgovR9gLgYFwDQIeuYi9TM= github.com/gorilla/mux v1.5.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY= +github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= diff --git a/supernode/server/0.3_bridge.go b/supernode/server/0.3_bridge.go index 2311aa11d..164a0288f 100644 --- a/supernode/server/0.3_bridge.go +++ b/supernode/server/0.3_bridge.go @@ -29,6 +29,7 @@ import ( sutil "github.com/dragonflyoss/Dragonfly/supernode/util" "github.com/go-openapi/strfmt" + "github.com/gorilla/schema" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -68,10 +69,25 @@ var resultMap = map[string]string{ } func (s *Server) registry(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) { - reader := req.Body request := &types.TaskRegisterRequest{} - if err := json.NewDecoder(reader).Decode(request); err != nil { - return errors.Wrap(errortypes.ErrInvalidValue, err.Error()) + + // parse request.Body to the types.TaskRegisterRequest struct + ct := req.Header.Get("Content-Type") + if ct == "application/x-www-form-urlencoded" { + if err := req.ParseForm(); err != nil { + return errors.Wrapf(errortypes.ErrInvalidValue, "failed to parse the request body as a form: %v", err) + } + + decoder := schema.NewDecoder() + err = decoder.Decode(request, req.PostForm) + if err != nil { + return errors.Wrap(errortypes.ErrInvalidValue, err.Error()) + } + } else { + reader := req.Body + if err := json.NewDecoder(reader).Decode(request); err != nil { + return errors.Wrap(errortypes.ErrInvalidValue, err.Error()) + } } if err := request.Validate(strfmt.NewFormats()); err != nil {