支持重定向, 自定义内容输出
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user