@@ -16,17 +16,20 @@ import (
1616 "github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/context_type"
1717 utilsV3 "github.com/ClessLi/bifrost/pkg/resolv/V3/nginx/configuration/utils"
1818
19+ logV1 "github.com/ClessLi/component-base/pkg/log/v1"
20+
1921 "github.com/marmotedu/errors"
2022)
2123
2224var (
23- dirHTTPProxyPassMustCompile = regexp .MustCompile (`^\s*proxy_pass\s+("\s*https?://[^";\s#]+"|'\s*https?://[^';\s#]+'|\s*https?://[^;\s#]+)` )
25+ dirHTTPProxyPassMustCompile = regexp .MustCompile (`^\s*proxy_pass\s+("\s*https?://[^";\s#]+"|'\s*https?://[^';\s#]+'|\s*https?://[^;\s#]+|\s*\$ )` )
2426 dirStreamProxyPassMustCompile = regexp .MustCompile (`^\s*proxy_pass\s+(` + S1 + `)$` )
2527 httpURLMustCompile = regexp .MustCompile (`^(http|https)://([^/]+\S*)$` )
2628 addrAndURIMustCompile = regexp .MustCompile (`^([^/]+)(/\S*)?$` )
2729 streamAddrWithPortMustCompile = regexp .MustCompile (`^([^/:\s]+):(\d+)$` )
30+ streamVariableAddrMustCompile = regexp .MustCompile (`^[^/\s$]*\$\S+$` )
2831 streamUpstreamMustCompile = regexp .MustCompile (`^([^/\s]+)$` )
29- streamUnixAddrMustCompile = regexp .MustCompile (`^unix:(/[^/]\s *)$` )
32+ streamUnixAddrMustCompile = regexp .MustCompile (`^unix:(/[^/]\S *)$` )
3033 addrWithPortMustCompile = regexp .MustCompile (`^([^/:\s]+):(\d+)` )
3134 upstreamSrvDirMustCompile = regexp .MustCompile (`^server\s+(\S+)` )
3235)
@@ -250,6 +253,11 @@ func (h *HTTPProxyPass) ReparseParams() (err error) {
250253 h .URI = uri
251254 }()
252255
256+ // return nil, if unknown protocol
257+ if protocol == "unknown" {
258+ return nil
259+ }
260+
253261 // parse IPv4s
254262 ipv4s , err := utilsV3 .ResolveDomainNameToIPv4 (host )
255263 if err == nil {
@@ -356,6 +364,10 @@ func parseHTTPURL(url string) (protocol, host, uri string, port uint16, err erro
356364 if urlMatch := httpURLMustCompile .FindStringSubmatch (url ); len (urlMatch ) == 3 {
357365 protocol = urlMatch [1 ]
358366 addressAndURI = urlMatch [2 ]
367+ } else if url [0 ] == '$' {
368+ protocol = "unknown"
369+
370+ return protocol , host , uri , port , err
359371 } else {
360372 err = errors .WithCode (code .ErrV3InvalidOperation , "the URL protocol must be `http` or `https`" )
361373
@@ -584,6 +596,11 @@ func (s *StreamProxyPass) ReparseParams() (err error) {
584596 return errors .WithCode (code .ErrV3InvalidOperation , "the port must be an integer, error: %s" , err .Error ())
585597 }
586598 port = uint16 (p )
599+ case streamVariableAddrMustCompile .MatchString (address ):
600+ s .OriginalAddress = address
601+ s .Addresses = proxiedAddrs
602+
603+ return nil
587604 case streamUpstreamMustCompile .MatchString (address ): // pass upstream server, not proxied address
588605 upstreamServer = streamUpstreamMustCompile .FindStringSubmatch (address )[1 ]
589606 case streamUnixAddrMustCompile .MatchString (address ):
@@ -788,17 +805,20 @@ func (t *tmpProxyPass) verifyAndInitTo() context.Context {
788805 var p ProxyPass
789806
790807 var verifyErr error
808+ logV1 .Debugf ("parsing tmp proxy_pass(%s)" , t .Value ())
791809 if dirHTTPProxyPassMustCompile .MatchString (t .Value ()) { //nolint:nestif
792810 hp := & HTTPProxyPass {Directive : t .Directive }
793811 verifyErr = hp .PosVerify ()
794812 if verifyErr == nil {
813+ logV1 .Debugf ("tmp proxy_pass(%s) has been parsed to HTTP proxy_pass" , t .Value ())
795814 p = hp
796815 }
797816 }
798817 if p == nil && dirStreamProxyPassMustCompile .MatchString (t .Value ()) {
799818 sp := & StreamProxyPass {Directive : t .Directive }
800819 verifyErr = sp .PosVerify ()
801820 if verifyErr == nil {
821+ logV1 .Debugf ("tmp proxy_pass(%s) has been parsed to Stream proxy_pass" , t .Value ())
802822 p = sp
803823 }
804824 }
0 commit comments