From b20cb4b7c3d549fb83615f262dae0901fba884b9 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 14 Nov 2023 17:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=87=8D=E5=AE=9A=E5=90=91,?= =?UTF-8?q?=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=86=85=E5=AE=B9=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- server/logic/gateway_response.go | 25 ++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5b8b9fc..9f9f254 100644 --- a/go.mod +++ b/go.mod @@ -47,4 +47,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace fusen-basic v0.0.0 => gitee.com/fusenpack/fusen-basic v0.0.5-0.20231109081455-017a4a27ebc6 +replace fusen-basic v0.0.0 => gitee.com/fusenpack/fusen-basic v0.0.5-0.20231114092248-4bce975c1242 diff --git a/go.sum b/go.sum index caa3f64..37245d2 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitee.com/fusenpack/fusen-basic v0.0.5-0.20231109081455-017a4a27ebc6 h1:EfC/otGhF2/ghnIQeoolOY+KtvHryPtwBD4uyCWJxtU= -gitee.com/fusenpack/fusen-basic v0.0.5-0.20231109081455-017a4a27ebc6/go.mod h1:VTOMNVbG/jJBGUinI+/pn8MPsbkN7+gwk2DP8vncTkA= +gitee.com/fusenpack/fusen-basic v0.0.5-0.20231114092248-4bce975c1242 h1:/Mnolce7yH1XHhm+KtNGXZksn3I4O5HeUrXzdP/5mKA= +gitee.com/fusenpack/fusen-basic v0.0.5-0.20231114092248-4bce975c1242/go.mod h1:Zw6gt/0VwNmtG2Boqmo8+5H5AVuWsIVgCgp1ilkRyao= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= diff --git a/server/logic/gateway_response.go b/server/logic/gateway_response.go index d23c19f..c45cf2f 100644 --- a/server/logic/gateway_response.go +++ b/server/logic/gateway_response.go @@ -30,13 +30,30 @@ var fsProtoJSON = &runtime.JSONPb{ func ResponseHeaderMatcher(ctx context.Context, w http.ResponseWriter, resp proto.Message) error { headers := w.Header() - key := http.CanonicalHeaderKey("Grpc-Metadata-" + string(basic.GM_FusenResponse)) - if location, ok := headers[key]; ok { + key := http.CanonicalHeaderKey(basic.GM_FusenResponse.GrpcMetadataKey()) + if grpcResp, ok := headers[key]; ok { // w.Header().Set("Location", location[0]) // w.WriteHeader(http.StatusFound) + + // 判断自定返回的内容, 用html的页面返回等... + selfwrite := http.CanonicalHeaderKey(basic.GM_SelfWrite.GrpcMetadataKey()) + if sw, ok := headers[selfwrite]; ok { + w.WriteHeader(200) + w.Write([]byte(sw[0])) + return nil + } + + // 重定向 + redirect := http.CanonicalHeaderKey(basic.GM_Redirect.GrpcMetadataKey()) + if location, ok := headers[redirect]; ok { + w.WriteHeader(http.StatusFound) + w.Header().Set("Location", location[0]) + return nil + } + w.WriteHeader(200) - fsHeader := location[0] + fsHeader := grpcResp[0] var buf = bytes.NewBufferString(fsHeader[:len(fsHeader)-1] + ",") rdata, err := fsProtoJSON.Marshal(resp) if err != nil { @@ -47,7 +64,9 @@ func ResponseHeaderMatcher(ctx context.Context, w http.ResponseWriter, resp prot buf.WriteString(`}`) w.Write(buf.Bytes()) + return nil } + w.Write([]byte("GM_FusenResponse error")) return nil }