Skip to content

Commit

Permalink
use a CustomRequestDecoder to handle properly the misbehaving request…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
umbynos committed Sep 5, 2023
1 parent 2047a96 commit 05344f2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion v2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v2

import (
"context"
"encoding/json"
"net/http"
"path/filepath"

Expand Down Expand Up @@ -56,7 +57,7 @@ func Server(home string) http.Handler {
Indexes: &indexesSvc,
}
toolsEndpoints := toolssvc.NewEndpoints(&toolsSvc)
toolsServer := toolssvr.New(toolsEndpoints, mux, goahttp.RequestDecoder, goahttp.ResponseEncoder, errorHandler(logger), nil)
toolsServer := toolssvr.New(toolsEndpoints, mux, CustomRequestDecoder, goahttp.ResponseEncoder, errorHandler(logger), nil)
toolssvr.Mount(mux, toolsServer)

// Mount middlewares
Expand All @@ -76,3 +77,15 @@ func errorHandler(logger *logrus.Logger) func(context.Context, http.ResponseWrit
logger.Printf("[%s] ERROR: %s", id, err.Error())
}
}

// CustomRequestDecoder overrides the RequestDecoder provided by goahttp package
// It returns always a json.NewDecoder for legacy reasons:
// The web editor sends always request to the agent setting "Content-Type: text/plain"
// even when it should set "Content-Type: application/json". This breaks the parsing with:
// "can't decode text/plain to *server.InstallRequestBody" error message.
// This was working before the bump to goa v3 only because a "text/plain" decoder was not implemented
// and it was fallbacking to the json decoder. (https://github.com/goadesign/goa/pull/2310)

func CustomRequestDecoder(r *http.Request) goahttp.Decoder {
return json.NewDecoder(r.Body)
}

0 comments on commit 05344f2

Please # to comment.