This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.14 by this push:
     new a7427c01 fix: forward original status code and body (#3342)
a7427c01 is described below

commit a7427c01e75006cea4cb41e135b39ede2b300903
Author: mindlesscloud <[email protected]>
AuthorDate: Sun Oct 9 15:38:53 2022 +0800

    fix: forward original status code and body (#3342)
---
 api/router.go              |  6 +++++-
 plugins/core/plugin_api.go |  7 ++++---
 plugins/jira/api/proxy.go  | 15 ++-------------
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/api/router.go b/api/router.go
index 4ad4e98d..66277842 100644
--- a/api/router.go
+++ b/api/router.go
@@ -112,7 +112,11 @@ func handlePluginCall(pluginName string, handler 
core.ApiResourceHandler) func(c
                                c.Data(status, output.File.ContentType, 
output.File.Data)
                                return
                        }
-                       shared.ApiOutputSuccess(c, output.Body, status)
+                       if blob, ok := output.Body.([]byte); ok && 
output.ContentType != "" {
+                               c.Data(status, output.ContentType, blob)
+                       } else {
+                               shared.ApiOutputSuccess(c, output.Body, status)
+                       }
                } else {
                        shared.ApiOutputSuccess(c, nil, http.StatusOK)
                }
diff --git a/plugins/core/plugin_api.go b/plugins/core/plugin_api.go
index 76dfa416..b882a7c8 100644
--- a/plugins/core/plugin_api.go
+++ b/plugins/core/plugin_api.go
@@ -39,9 +39,10 @@ type OutputFile struct {
 
 // Describe response data of a api
 type ApiResourceOutput struct {
-       Body   interface{} // response body
-       Status int
-       File   *OutputFile
+       Body        interface{} // response body
+       Status      int
+       File        *OutputFile
+       ContentType string
 }
 
 type ApiResourceHandler func(input *ApiResourceInput) (*ApiResourceOutput, 
errors.Error)
diff --git a/plugins/jira/api/proxy.go b/plugins/jira/api/proxy.go
index 47934e98..4d767f6b 100644
--- a/plugins/jira/api/proxy.go
+++ b/plugins/jira/api/proxy.go
@@ -19,21 +19,16 @@ package api
 
 import (
        "context"
-       "encoding/json"
        "fmt"
-       "github.com/apache/incubator-devlake/errors"
        "io"
        "time"
 
+       "github.com/apache/incubator-devlake/errors"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/jira/models"
 )
 
-const (
-       TimeOut = 10 * time.Second
-)
-
 func Proxy(input *core.ApiResourceInput) (*core.ApiResourceOutput, 
errors.Error) {
        connection := &models.JiraConnection{}
        err := connectionHelper.First(connection, input.Params)
@@ -63,11 +58,5 @@ func Proxy(input *core.ApiResourceInput) 
(*core.ApiResourceOutput, errors.Error)
        if err != nil {
                return nil, err
        }
-       // verify response body is json
-       var tmp interface{}
-       err = errors.Convert(json.Unmarshal(body, &tmp))
-       if err != nil {
-               return nil, err
-       }
-       return &core.ApiResourceOutput{Status: resp.StatusCode, Body: 
json.RawMessage(body)}, nil
+       return &core.ApiResourceOutput{Status: resp.StatusCode, ContentType: 
resp.Header.Get("Content-Type"), Body: body}, nil
 }

Reply via email to