mark4z commented on a change in pull request #307:
URL: https://github.com/apache/dubbo-go-pixiu/pull/307#discussion_r772368219



##########
File path: pkg/common/http/manager.go
##########
@@ -58,35 +62,75 @@ func (hcm *HttpConnectionManager) OnData(hc 
*pch.HttpContext) error {
        if err != nil {
                return err
        }
-       hcm.addFilter(hc)
        hcm.handleHTTPRequest(hc)
        return nil
 }
 
 // handleHTTPRequest handle http request
 func (hcm *HttpConnectionManager) handleHTTPRequest(c *pch.HttpContext) {
-       if len(c.Filters) > 0 {
-               c.Next()
-               return
+       filterChain := hcm.filterManager.CreateFilterChain(c)
+
+       // recover any err when filterChain run
+       defer func() {
+               if err := recover(); err != nil {
+                       logger.Warnf("[dubbopixiu go] Occur An Unexpected Err: 
%+v", err)
+                       c.SendLocalReply(http.StatusInternalServerError, 
[]byte(fmt.Sprintf("Occur An Unexpected Err: %v", err)))
+               }
+       }()
+
+       //todo timeout
+       filterChain.OnDecode(c)
+       hcm.buildTargetResponse(c)
+       filterChain.OnEncode(c)
+       hcm.writeResponse(c)
+}
+
+func (hcm *HttpConnectionManager) writeResponse(c *pch.HttpContext) {
+       if !c.LocalReply() {
+               writer := c.Writer
+               writer.WriteHeader(c.GetStatusCode())
+               if _, err := writer.Write(c.TargetResp.Data); err != nil {
+                       panic(err)
+               }
        }
-       // TODO redirect
 }
 
-func (hcm *HttpConnectionManager) addFilter(ctx *pch.HttpContext) {
-       for _, f := range hcm.filterManager.GetFilters() {
-               if err := (*f).PrepareFilterChain(ctx); err != nil {
-                       logger.Warnf("PrepareFilterChain error %s", err)
+func (hcm *HttpConnectionManager) buildTargetResponse(c *pch.HttpContext) {
+       if !c.LocalReply() {

Review comment:
       return提前短路没问题,至于filter中断的日志,由filter打印比较好。毕竟acl filter也会打印




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to