You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/01/12 07:42:09 UTC
(incubator-devlake) branch release-v0.20 updated: fix(api): proxy api pass through x-headers (#6788) (#6798)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch release-v0.20
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.20 by this push:
new 60556bc33 fix(api): proxy api pass through x-headers (#6788) (#6798)
60556bc33 is described below
commit 60556bc332de0ef07b7dc975b17f90e2f181886e
Author: Leric Zhang <li...@merico.dev>
AuthorDate: Fri Jan 12 15:42:04 2024 +0800
fix(api): proxy api pass through x-headers (#6788) (#6798)
---
backend/core/plugin/plugin_api.go | 1 +
backend/helpers/pluginhelper/api/remote_api_helper.go | 13 ++++++++++++-
backend/server/api/router.go | 7 +++++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/backend/core/plugin/plugin_api.go b/backend/core/plugin/plugin_api.go
index 5b0c613ea..d1eb1a07a 100644
--- a/backend/core/plugin/plugin_api.go
+++ b/backend/core/plugin/plugin_api.go
@@ -51,6 +51,7 @@ type ApiResourceOutput struct {
Status int
File *OutputFile
ContentType string
+ Header http.Header // optional response header
}
type ApiResourceHandler func(input *ApiResourceInput) (*ApiResourceOutput, errors.Error)
diff --git a/backend/helpers/pluginhelper/api/remote_api_helper.go b/backend/helpers/pluginhelper/api/remote_api_helper.go
index 80d3eeedb..fd6d77bf3 100644
--- a/backend/helpers/pluginhelper/api/remote_api_helper.go
+++ b/backend/helpers/pluginhelper/api/remote_api_helper.go
@@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"strconv"
+ "strings"
"github.com/apache/incubator-devlake/core/log"
@@ -171,7 +172,17 @@ func (r *RemoteApiHelper[Conn, Scope, ApiScope, Group]) ProxyApiGet(conn plugin.
if err != nil {
return nil, err
}
- return &plugin.ApiResourceOutput{Status: resp.StatusCode, Body: json.RawMessage(body)}, nil
+ headers := http.Header{}
+ for k, vs := range resp.Header {
+ // skip headers doesn't start with "x-"
+ if !strings.HasPrefix(strings.ToLower(k), "x-") {
+ continue
+ }
+ for _, v := range vs {
+ headers.Add(k, v)
+ }
+ }
+ return &plugin.ApiResourceOutput{Status: resp.StatusCode, Body: json.RawMessage(body), Header: headers}, nil
}
// PrepareFirstPageToken prepares the first page token
diff --git a/backend/server/api/router.go b/backend/server/api/router.go
index be2e0f39a..6957044de 100644
--- a/backend/server/api/router.go
+++ b/backend/server/api/router.go
@@ -145,6 +145,13 @@ func handlePluginCall(basicRes context.BasicRes, pluginName string, handler plug
if status < http.StatusContinue {
status = http.StatusOK
}
+ if output.Header != nil {
+ for k, vs := range output.Header {
+ for _, v := range vs {
+ c.Header(k, v)
+ }
+ }
+ }
if output.File != nil {
c.Data(status, output.File.ContentType, output.File.Data)
return