Alanxtl commented on code in PR #692:
URL: https://github.com/apache/dubbo-go-pixiu/pull/692#discussion_r2261785615


##########
pkg/filter/llm/proxy/filter.go:
##########
@@ -48,188 +49,271 @@ func init() {
 }
 
 type (
-       // Plugin is http filter plugin.
-       Plugin struct {
-       }
-       // FilterFactory is http filter instance
+       // Plugin is the main plugin entrypoint.
+       Plugin struct{}
+
+       // FilterFactory creates filter instances.
        FilterFactory struct {
                cfg    *Config
                client http.Client
        }
+
+       // Filter is the processing entity for each request.
        Filter struct {
-               client http.Client
-               scheme string
+               client         http.Client
+               scheme         string
+               strategy       *Strategy
+               clusterManager *server.ClusterManager
        }
-       // Config describe the config of FilterFactory
+
+       // Config describes the top-level configuration for the filter.
+       // Note: Strategy-specific configurations are now defined on the 
endpoints.
        Config struct {
                Timeout             time.Duration `yaml:"timeout" 
json:"timeout,omitempty"`
                MaxIdleConns        int           `yaml:"maxIdleConns" 
json:"maxIdleConns,omitempty"`
                MaxIdleConnsPerHost int           `yaml:"maxIdleConnsPerHost" 
json:"maxIdleConnsPerHost,omitempty"`
                MaxConnsPerHost     int           `yaml:"maxConnsPerHost" 
json:"maxConnsPerHost,omitempty"`
                Scheme              string        `yaml:"scheme" 
json:"scheme,omitempty" default:"http"`
        }
+
+       RequestExecutor struct {
+               hc             *contexthttp.HttpContext
+               filter         *Filter
+               clusterName    string
+               clusterManager *server.ClusterManager
+       }
 )
 
+// Kind returns the unique name of this filter.
 func (p *Plugin) Kind() string {
        return Kind
 }
 
+// CreateFilterFactory creates a new factory instance for this filter.
 func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) {
        return &FilterFactory{cfg: &Config{}}, nil
 }
 
+// Config returns the configuration struct for the factory.
 func (factory *FilterFactory) Config() any {
        return factory.cfg
 }
 
+// Apply initializes the factory from its configuration.
 func (factory *FilterFactory) Apply() error {
        scheme := strings.TrimSpace(strings.ToLower(factory.cfg.Scheme))
-
        if scheme != "http" && scheme != "https" {
                return fmt.Errorf("%s: scheme must be http or https", Kind)
        }
-
        factory.cfg.Scheme = scheme
 
        cfg := factory.cfg
-       client := http.Client{
+       factory.client = http.Client{
                Timeout: cfg.Timeout,
-               Transport: http.RoundTripper(&http.Transport{
+               Transport: &http.Transport{
                        MaxIdleConns:        cfg.MaxIdleConns,
                        MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost,
                        MaxConnsPerHost:     cfg.MaxConnsPerHost,
-               }),
+               },
        }
-       factory.client = client
        return nil
 }
 
+// PrepareFilterChain creates a new Filter instance for a request chain.
 func (factory *FilterFactory) PrepareFilterChain(ctx *contexthttp.HttpContext, 
chain filter.FilterChain) error {
-       //reuse http client
-       f := &Filter{factory.client, factory.cfg.Scheme}
+       f := &Filter{
+               client:         factory.client,
+               scheme:         factory.cfg.Scheme,
+               strategy:       &Strategy{},
+               clusterManager: server.GetClusterManager(),
+       }
        chain.AppendDecodeFilters(f)
        return nil
 }
 
+// Decode is the main entry point for processing an incoming request.
 func (f *Filter) Decode(hc *contexthttp.HttpContext) filter.FilterStatus {
        rEntry := hc.GetRouteEntry()
        if rEntry == nil {
-               bt, _ := json.Marshal(contexthttp.ErrResponse{Message: "no 
route entry"})
-               hc.SendLocalReply(http.StatusBadRequest, bt)
+               sendJSONError(hc, http.StatusBadRequest, "no route entry found 
for request")
                return filter.Stop
        }
-
        logger.Debugf("[dubbo-go-pixiu] client choose endpoint from cluster: 
%v", rEntry.Cluster)
 
-       var (
-               clusterName    = rEntry.Cluster
-               clusterManager = server.GetClusterManager()
-               endpoint       = clusterManager.PickEndpoint(clusterName, hc)
-       )
-
-       if endpoint == nil {
-               logger.Debugf("[dubbo-go-pixiu] cluster not found endpoint")
-               bt, _ := json.Marshal(contexthttp.ErrResponse{Message: "cluster 
not found endpoint"})
-               hc.SendLocalReply(http.StatusServiceUnavailable, bt)
+       // Ensure the request body can be re-read for retries
+       if err := f.prepareRequestBody(hc); err != nil {
+               sendJSONError(hc, http.StatusInternalServerError, 
fmt.Sprintf("failed to read request body: %v", err))
                return filter.Stop
        }
+       defer hc.Request.Body.Close()

Review Comment:
   others all done
   
   我在195行把request重新赋值了,这里close的是两个不同的hc.Request.Body



-- 
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