liuxiran commented on a change in pull request #979:
URL: https://github.com/apache/apisix-dashboard/pull/979#discussion_r544826857



##########
File path: api/internal/handler/route/route.go
##########
@@ -397,3 +401,61 @@ func Exist(c *gin.Context) (interface{}, error) {
 
        return nil, nil
 }
+
+type ParamsInput struct {
+       URL          string              `json:"url,omitempty"`
+       BodyParams   map[string]string   `json:"bodyParams,omitempty"`
+       Method       string              `json:"method,omitempty"`
+       HeaderParams map[string][]string `json:"headerParams,omitempty"`
+}
+
+type Result struct {
+       Code    int         `json:"code,omitempty"`
+       Message string      `json:"message,omitempty"`
+       Data    interface{} `json:"data,omitempty"`
+}
+
+func (h *Handler) DebugRequestForwarding(c droplet.Context) (interface{}, 
error) {
+       paramsInput := c.Input().(*ParamsInput)
+       bodyParams, _ := json.Marshal(paramsInput.BodyParams)
+       client := &http.Client{}
+
+       client.Timeout = 5 * time.Second
+       req, err := http.NewRequest(strings.ToUpper(paramsInput.Method), 
paramsInput.URL, strings.NewReader(string(bodyParams)))
+       if err != nil {
+               return &data.SpecCodeResponse{StatusCode: 
http.StatusInternalServerError}, err
+       }
+       for k, v := range paramsInput.HeaderParams {
+               for _, v1 := range v {
+                       req.Header.Add(k, v1)
+               }
+       }
+       resp, err := client.Do(req)
+       if err != nil {
+               return &data.SpecCodeResponse{StatusCode: 
http.StatusInternalServerError}, err
+       }
+       defer func() {
+               if resp != nil {
+                       _ = resp.Body.Close()
+               }
+       }()
+
+       body, err := ioutil.ReadAll(resp.Body)
+       if err != nil {
+               return &data.SpecCodeResponse{StatusCode: 
http.StatusInternalServerError}, err
+       }
+       returnData := make(map[string]interface{})
+       result := &Result{}
+       err = json.Unmarshal(body, &returnData)
+       if err != nil {
+               result.Code = resp.StatusCode
+               result.Message = resp.Status
+               result.Data = string(body)
+       } else {
+               result.Code = resp.StatusCode
+               result.Message = resp.Status
+               result.Data = returnData
+
+       }

Review comment:
       updated, please recheck when you have time @nic-chen ^_^
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to