marsevilspirit commented on code in PR #657:
URL: https://github.com/apache/dubbo-go-pixiu/pull/657#discussion_r2046788060


##########
pkg/filter/metric/metric.go:
##########
@@ -25,7 +25,9 @@ import (
 
 import (
        "github.com/pkg/errors"
+
        "go.opentelemetry.io/otel/attribute"
+

Review Comment:
   remove the blank space?



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"
+       "net/url"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+       "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+const (
+       // Kind is the kind of Fallback.
+       Kind = "dgp.filter.http.sse.httpproxy"
+)
+
+func init() {
+       filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+       // Plugin is http filter plugin.
+       Plugin struct {
+       }
+       // FilterFactory is http filter instance
+       FilterFactory struct {
+               cfg    *Config
+               client stdhttp.Client
+       }
+       //Filter
+       Filter struct {
+               client stdhttp.Client
+       }
+       // Config describe the config of FilterFactory
+       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"`
+       }
+)
+
+func (p *Plugin) Kind() string {
+       return Kind
+}
+
+func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) {
+       return &FilterFactory{cfg: &Config{}}, nil
+}
+
+func (factory *FilterFactory) Config() interface{} {
+       return factory.cfg
+}
+
+func (factory *FilterFactory) Apply() error {
+       cfg := factory.cfg
+       client := stdhttp.Client{
+               Timeout: cfg.Timeout,
+               Transport: stdhttp.RoundTripper(&stdhttp.Transport{
+                       MaxIdleConns:        cfg.MaxIdleConns,
+                       MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost,
+                       MaxConnsPerHost:     cfg.MaxConnsPerHost,
+               }),
+       }
+       factory.client = client
+       return nil
+}
+
+func (factory *FilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain 
filter.FilterChain) error {
+       //reuse http client
+       f := &Filter{factory.client}
+       chain.AppendDecodeFilters(f)
+       return nil
+}
+
+func (f *Filter) Decode(hc *http.HttpContext) filter.FilterStatus {
+

Review Comment:
   remove the blank space.



##########
pkg/common/http/manager_SSE_test.go:
##########
@@ -0,0 +1,172 @@
+/*

Review Comment:
   I prefer to rename the file to manager_test.go.



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"
+       "net/url"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+       "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+const (
+       // Kind is the kind of Fallback.
+       Kind = "dgp.filter.http.sse.httpproxy"
+)
+
+func init() {
+       filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+       // Plugin is http filter plugin.
+       Plugin struct {
+       }
+       // FilterFactory is http filter instance
+       FilterFactory struct {
+               cfg    *Config
+               client stdhttp.Client
+       }
+       //Filter
+       Filter struct {
+               client stdhttp.Client
+       }
+       // Config describe the config of FilterFactory
+       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"`
+       }
+)
+
+func (p *Plugin) Kind() string {
+       return Kind
+}
+
+func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) {
+       return &FilterFactory{cfg: &Config{}}, nil
+}
+
+func (factory *FilterFactory) Config() interface{} {
+       return factory.cfg
+}
+
+func (factory *FilterFactory) Apply() error {

Review Comment:
   factory -> ff



##########
pkg/client/response.go:
##########
@@ -17,12 +17,38 @@
 
 package client
 
-// Response response from endpoint
-type Response struct {
+import (
+       "io"
+)
+
+type Response interface {
+       IsStream() bool
+}
+
+// ByteResponse response from endpoint
+type ByteResponse struct {

Review Comment:
   rename UnaryResponse better?



##########
pkg/common/http/manager.go:
##########
@@ -107,16 +108,88 @@ func (hcm *HttpConnectionManager) handleHTTPRequest(c 
*pch.HttpContext) {
        //todo timeout
        filterChain.OnDecode(c)
        hcm.buildTargetResponse(c)
+       //todo: stream resp has to set HTTP Server's WriteTimeout to 0, need to 
check it
+       //todo: stream resp ignores OnEncode stage
        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 {
-                       logger.Errorf("write response error: %s", err)
+               c.Writer.WriteHeader(c.GetStatusCode())
+               if c.TargetResp != nil {
+                       switch res := c.TargetResp.(type) {
+                       case *client.ByteResponse:
+                               _, err := c.Writer.Write(res.Data)
+                               if err != nil {
+                                       logger.Errorf("Write response failed: 
%v", err)
+                               }
+                       case *client.StreamResponse:
+                               // create ctx helps goroutine exit
+                               ctx, cancel := context.WithCancel(c.Ctx)
+                               defer cancel()
+
+                               dataCh := make(chan []byte)
+                               errCh := make(chan error, 1)

Review Comment:
   change to dataC and errC?



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"

Review Comment:
   remove stdhttp



##########
pkg/context/http/context.go:
##########
@@ -59,7 +59,7 @@ type HttpContext struct {
        // localReplyBody: happen error
        localReplyBody []byte
        // the response context will return.
-       TargetResp *client.Response
+       TargetResp interface{}

Review Comment:
   I agree.



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"
+       "net/url"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+       "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+const (
+       // Kind is the kind of Fallback.
+       Kind = "dgp.filter.http.sse.httpproxy"
+)
+
+func init() {
+       filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+       // Plugin is http filter plugin.
+       Plugin struct {
+       }
+       // FilterFactory is http filter instance
+       FilterFactory struct {
+               cfg    *Config
+               client stdhttp.Client
+       }
+       //Filter
+       Filter struct {
+               client stdhttp.Client
+       }
+       // Config describe the config of FilterFactory
+       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"`
+       }
+)
+
+func (p *Plugin) Kind() string {
+       return Kind
+}
+
+func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) {
+       return &FilterFactory{cfg: &Config{}}, nil
+}
+
+func (factory *FilterFactory) Config() interface{} {
+       return factory.cfg
+}
+
+func (factory *FilterFactory) Apply() error {
+       cfg := factory.cfg
+       client := stdhttp.Client{
+               Timeout: cfg.Timeout,
+               Transport: stdhttp.RoundTripper(&stdhttp.Transport{
+                       MaxIdleConns:        cfg.MaxIdleConns,
+                       MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost,
+                       MaxConnsPerHost:     cfg.MaxConnsPerHost,
+               }),
+       }
+       factory.client = client
+       return nil
+}
+
+func (factory *FilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain 
filter.FilterChain) error {

Review Comment:
   factory -> ff



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"
+       "net/url"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+       "github.com/apache/dubbo-go-pixiu/pkg/context/http"

Review Comment:
   alias contexthttp



##########
pkg/common/mock/routerfilter.go:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package mock
+
+import (
+       "encoding/json"
+       "fmt"
+       stdhttp "net/http"
+       "net/url"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+       "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+const (
+       // Kind is the kind of Fallback.
+       Kind = "dgp.filter.http.sse.httpproxy"
+)
+
+func init() {
+       filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+       // Plugin is http filter plugin.
+       Plugin struct {
+       }
+       // FilterFactory is http filter instance
+       FilterFactory struct {
+               cfg    *Config
+               client stdhttp.Client
+       }
+       //Filter
+       Filter struct {
+               client stdhttp.Client
+       }
+       // Config describe the config of FilterFactory
+       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"`
+       }
+)
+
+func (p *Plugin) Kind() string {
+       return Kind
+}
+
+func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) {
+       return &FilterFactory{cfg: &Config{}}, nil
+}
+
+func (factory *FilterFactory) Config() interface{} {

Review Comment:
   factory -> ff



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