Skip to content

Commit

Permalink
fix(be): change bodyParams to string to accept any content-type (#1202)
Browse files Browse the repository at this point in the history
* fix: change bodyParams to string to accept any content-type

* fix: ci error

* fix: change bodyparam to type string in e2e test case

* fix: ci

Co-authored-by: 琚致远 <juzhiyuan@apache.org>
  • Loading branch information
liuxiran and juzhiyuan committed Jan 7, 2021
1 parent 72f2195 commit 4e4332d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions api/internal/handler/route_online_debug/route_online_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (h *Handler) ApplyRoute(r *gin.Engine) {
type ParamsInput struct {
URL string `json:"url,omitempty"`
RequestProtocol string `json:"request_protocol,omitempty"`
BodyParams map[string]string `json:"body_params,omitempty"`
BodyParams string `json:"body_params,omitempty"`
Method string `json:"method,omitempty"`
HeaderParams map[string][]string `json:"header_params,omitempty"`
}
Expand Down Expand Up @@ -88,11 +88,11 @@ type HTTPProtocolSupport struct {

func (h *HTTPProtocolSupport) RequestForwarding(c droplet.Context) (interface{}, error) {
paramsInput := c.Input().(*ParamsInput)
bodyParams, _ := json.Marshal(paramsInput.BodyParams)
bodyParams := paramsInput.BodyParams
client := &http.Client{}

client.Timeout = 5 * time.Second
req, err := http.NewRequest(strings.ToUpper(paramsInput.Method), paramsInput.URL, strings.NewReader(string(bodyParams)))
req, err := http.NewRequest(strings.ToUpper(paramsInput.Method), paramsInput.URL, strings.NewReader(bodyParams))
if err != nil {
return &data.SpecCodeResponse{StatusCode: http.StatusInternalServerError}, err
}
Expand Down
5 changes: 1 addition & 4 deletions api/test/e2e/route_online_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ func TestRoute_Online_Debug_Route_With_Body_Params(t *testing.T) {
"url": "` + APISIXInternalUrl + `/hello",
"request_protocol": "http",
"method": "POST",
"body_params": {
"name": "test",
"desc": "online debug route with body params"
}
"body_params": "{\"name\":\"test\",\"desc\":\"online debug route with body params\"}"
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
Expand Down

0 comments on commit 4e4332d

Please sign in to comment.