Skip to content

Commit 98fdf66

Browse files
committed
use a CustomRequestDecoder to handle properly the misbehaving requests of the Web Editor
The requests sent uses `text/plain` Content-Type when they should be using `application/json` This commit restores the old behavior, using always a json Decoder
1 parent 2047a96 commit 98fdf66

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

v2/http.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package v2
1717

1818
import (
1919
"context"
20+
"encoding/json"
2021
"net/http"
2122
"path/filepath"
2223

@@ -56,7 +57,7 @@ func Server(home string) http.Handler {
5657
Indexes: &indexesSvc,
5758
}
5859
toolsEndpoints := toolssvc.NewEndpoints(&toolsSvc)
59-
toolsServer := toolssvr.New(toolsEndpoints, mux, goahttp.RequestDecoder, goahttp.ResponseEncoder, errorHandler(logger), nil)
60+
toolsServer := toolssvr.New(toolsEndpoints, mux, CustomRequestDecoder, goahttp.ResponseEncoder, errorHandler(logger), nil)
6061
toolssvr.Mount(mux, toolsServer)
6162

6263
// Mount middlewares
@@ -76,3 +77,14 @@ func errorHandler(logger *logrus.Logger) func(context.Context, http.ResponseWrit
7677
logger.Printf("[%s] ERROR: %s", id, err.Error())
7778
}
7879
}
80+
81+
// CustomRequestDecoder overrides the RequestDecoder provided by goahttp package
82+
// It returns always a json.NewDecoder for legacy reasons:
83+
// The web editor sends always request to the agent setting "Content-Type: text/plain"
84+
// even when it should set "Content-Type: application/json". This breaks the parsing with:
85+
// "can't decode text/plain to *server.InstallRequestBody" error message.
86+
// This was working before the bump to goa v3 only because a "text/plain" decoder was not implemented
87+
// and it was fallbacking to the json decoder. (https://github.com/goadesign/goa/pull/2310)
88+
func CustomRequestDecoder(r *http.Request) goahttp.Decoder {
89+
return json.NewDecoder(r.Body)
90+
}

0 commit comments

Comments
 (0)