Skip to content

Commit 75faff9

Browse files
committed
Merge branch 'refs/heads/develop'
2 parents c34d53b + 7fca196 commit 75faff9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# 项目介绍
88

99
**Bifrost**
10-
是基于golang语言开发的项目,它目前还处于测试阶段,用于对Nginx配置文件解析并提供配置文件展示和修改的接口,支持json、字符串格式与golang结构相互转换。该项目持续更新中。最新可用版本为[v1.1.0-alpha.10](https://github.com/ClessLi/bifrost/tree/v1.1.0-alpha.10)
10+
是基于golang语言开发的项目,它目前还处于测试阶段,用于对Nginx配置文件解析并提供配置文件展示和修改的接口,支持json、字符串格式与golang结构相互转换。该项目持续更新中。最新可用版本为[v1.1.0-alpha.11](https://github.com/ClessLi/bifrost/tree/v1.1.0-alpha.11)
1111

1212
# 项目特点
1313

pkg/resolv/V3/nginx/configuration/context/local/proxy_pass.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2224
var (
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

Comments
 (0)