This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new d7f86531 feat: add scheme field in http proxy filter, enable httpproxy 
filter to make https call (#671)
d7f86531 is described below

commit d7f86531f30f1b1cb85025e9b7c277db0b3f1f23
Author: Alan <[email protected]>
AuthorDate: Thu May 1 10:41:21 2025 +0800

    feat: add scheme field in http proxy filter, enable httpproxy filter to 
make https call (#671)
    
    * feat: add HTTP/HTTPS scheme in http filter, enable http filter has the 
ability to make https call
    
    * change config validation location
    
    * revert
---
 pkg/filter/http/httpproxy/routerfilter.go | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/pkg/filter/http/httpproxy/routerfilter.go 
b/pkg/filter/http/httpproxy/routerfilter.go
index bc49ae96..cb98da47 100644
--- a/pkg/filter/http/httpproxy/routerfilter.go
+++ b/pkg/filter/http/httpproxy/routerfilter.go
@@ -19,9 +19,11 @@ package httpproxy
 
 import (
        "encoding/json"
+       "errors"
        "fmt"
        "net/http"
        "net/url"
+       "strings"
        "time"
 )
 
@@ -51,9 +53,9 @@ type (
                cfg    *Config
                client http.Client
        }
-       //Filter
        Filter struct {
                client http.Client
+               scheme string
        }
        // Config describe the config of FilterFactory
        Config struct {
@@ -61,6 +63,7 @@ type (
                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"`
        }
 )
 
@@ -77,6 +80,14 @@ func (factory *FilterFactory) Config() interface{} {
 }
 
 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{
                Timeout: cfg.Timeout,
@@ -92,7 +103,7 @@ func (factory *FilterFactory) Apply() error {
 
 func (factory *FilterFactory) PrepareFilterChain(ctx *contexthttp.HttpContext, 
chain filter.FilterChain) error {
        //reuse http client
-       f := &Filter{factory.client}
+       f := &Filter{factory.client, factory.cfg.Scheme}
        chain.AppendDecodeFilters(f)
        return nil
 }
@@ -124,7 +135,7 @@ func (f *Filter) Decode(hc *contexthttp.HttpContext) 
filter.FilterStatus {
 
        parsedURL := url.URL{
                Host:     endpoint.Address.GetAddress(),
-               Scheme:   "http",
+               Scheme:   f.scheme,
                Path:     r.URL.Path,
                RawQuery: r.URL.RawQuery,
        }
@@ -139,7 +150,8 @@ func (f *Filter) Decode(hc *contexthttp.HttpContext) 
filter.FilterStatus {
 
        resp, err := f.client.Do(req)
        if err != nil {
-               urlErr, ok := err.(*url.Error)
+               var urlErr *url.Error
+               ok := errors.As(err, &urlErr)
                if ok && urlErr.Timeout() {
                        hc.SendLocalReply(http.StatusGatewayTimeout, 
[]byte(err.Error()))
                        return filter.Stop

Reply via email to