支持重定向, 自定义内容输出
This commit is contained in:
parent
67387be192
commit
b20cb4b7c3
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user