Skip to content

Commit 323dbb1

Browse files
committed
BUG: Allows httpsPort to be valid
1 parent 98108bf commit 323dbb1

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

proxy/ha_proxy_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,43 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndWith
16451645
s.Equal(expectedData, actualData)
16461646
}
16471647

1648+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndWithDomain_Https() {
1649+
var actualData string
1650+
tmpl := s.TemplateContent
1651+
expectedData := fmt.Sprintf(
1652+
`%s
1653+
acl url_https_my-service-11111_0 path_beg /path
1654+
acl domain_https_my-service-11111_0 hdr_beg(host) -i domain-1-1 domain-1-2
1655+
use_backend https-my-service-1-be1111_0 if url_https_my-service-11111_0 domain_https_my-service-11111_0
1656+
acl url_https_my-service-21111_0 path_beg /path
1657+
acl domain_https_my-service-21111_0 hdr_beg(host) -i domain-2-1 domain-2-2
1658+
use_backend https-my-service-2-be1111_0 if url_https_my-service-21111_0 domain_https_my-service-21111_0%s`,
1659+
tmpl,
1660+
s.ServicesContent,
1661+
)
1662+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
1663+
actualData = string(data)
1664+
return nil
1665+
}
1666+
p := NewHaProxy(s.TemplatesPath, s.ConfigsPath)
1667+
for i := 1; i <= 2; i++ {
1668+
name := fmt.Sprintf("my-service-%d", i)
1669+
domain := fmt.Sprintf("domain-%d", i)
1670+
service := Service{
1671+
ServiceName: name,
1672+
PathType: "path_beg",
1673+
ServiceDest: []ServiceDest{
1674+
{HttpsPort: 1111, ServicePath: []string{"/path"}, ServiceDomain: []string{domain + "-1", domain + "-2"}},
1675+
},
1676+
}
1677+
p.AddService(service)
1678+
}
1679+
1680+
p.CreateConfigFromTemplates()
1681+
1682+
s.Equal(expectedData, actualData)
1683+
}
1684+
16481685
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDomainsForEachServiceDest() {
16491686
var actualData string
16501687
tmpl := s.TemplateContent

proxy/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getFrontTemplate(s Service) string {
7575
{{- end}}
7676
{{- end }}
7777
{{- if gt $sd.HttpsPort 0 }}
78-
use_backend https-{{$.AclName}}-be{{.HttpsPort}}_{{.Index}} if url_https_{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{if .ServicePathExclude}} !url_exclude_https_{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{end}}{{if .ServiceDomain}} domain_https{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{end}}{{.SrcHttpsPortAclName}}{{ $length := len .UserAgent.Value}}{{if gt $length 0}} user_agent_{{$.AclName}}_{{.UserAgent.AclName}}_{{.Index}}{{end}}
78+
use_backend https-{{$.AclName}}-be{{.HttpsPort}}_{{.Index}} if url_https_{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{if .ServicePathExclude}} !url_exclude_https_{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{end}}{{if .ServiceDomain}} domain_https_{{$.AclName}}{{.HttpsPort}}_{{.Index}}{{end}}{{.SrcHttpsPortAclName}}{{ $length := len .UserAgent.Value}}{{if gt $length 0}} user_agent_{{$.AclName}}_{{.UserAgent.AclName}}_{{.Index}}{{end}}
7979
{{- end}}
8080
{{- end}}
8181
{{- end}}`

server/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ func (m *serve) writeInternalServerError(w http.ResponseWriter, resp *Response,
389389
}
390390

391391
func (m *serve) hasPort(sd []proxy.ServiceDest) bool {
392-
return len(sd) > 0 && len(sd[0].Port) > 0
392+
HasPort := len(sd) > 0 && len(sd[0].Port) > 0
393+
HasHttpsPort := len(sd) > 0 && sd[0].HttpsPort > 0
394+
return HasPort || HasHttpsPort
393395
}
394396

395397
func getSliceFromString(input string) []string {

0 commit comments

Comments
 (0)