Skip to content

Commit

Permalink
Reverted #435
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Feb 24, 2018
1 parent 6da0ae2 commit f9955dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
35 changes: 35 additions & 0 deletions proxy/ha_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,41 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ForwardsToHttps_WhenRed
s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_usesHttpsRedirectCode() {
var actualData string
tmpl := s.TemplateContent
expectedData := fmt.Sprintf(
`%s
acl url_my-service1111_0 path_beg /path
acl domain_my-service1111_0 hdr_beg(host) -i my-domain.com
use_backend my-service-be1111_0 if url_my-service1111_0 domain_my-service1111_0
acl is_my-service_http hdr(X-Forwarded-Proto) http
http-request redirect scheme https code 301 if is_my-service_http url_my-service1111_0 domain_my-service1111_0
acl is_my-service_https hdr(X-Forwarded-Proto) https
http-request redirect scheme https code 301 if !is_my-service_https url_my-service1111_0 domain_my-service1111_0%s`,
tmpl,
s.ServicesContent,
)
writeFile = func(filename string, data []byte, perm os.FileMode) error {
actualData = string(data)
return nil
}
p := NewHaProxy(s.TemplatesPath, s.ConfigsPath)
dataInstance.Services["my-service"] = Service{
ServiceName: "my-service",
PathType: "path_beg",
RedirectWhenHttpProto: true,
AclName: "my-service",
ServiceDest: []ServiceDest{
{Port: "1111", ServicePath: []string{"/path"}, ServiceDomain: []string{"my-domain.com"}, HttpsRedirectCode: "301"},
},
}

p.CreateConfigFromTemplates()

s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ForwardsToDomain_WhenRedirectFromDomainIsSet() {
var actualData string
tmpl := s.TemplateContent
Expand Down
4 changes: 2 additions & 2 deletions proxy/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func getFrontTemplate(s Service) string {
{{- if eq .ReqMode "http"}}
{{- if ne .Port ""}}
acl is_{{$.AclName}}_http hdr(X-Forwarded-Proto) http
http-request redirect scheme https if is_{{$.AclName}}_http url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{.SrcPortAclName}}
http-request redirect scheme https{{if .HttpsRedirectCode}} code {{.HttpsRedirectCode}}{{end}} if is_{{$.AclName}}_http url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{.SrcPortAclName}}
acl is_{{$.AclName}}_https hdr(X-Forwarded-Proto) https
http-request redirect scheme https if !is_{{$.AclName}}_https url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{.SrcPortAclName}}
http-request redirect scheme https{{if .HttpsRedirectCode}} code {{.HttpsRedirectCode}}{{end}} if !is_{{$.AclName}}_https url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{.SrcPortAclName}}
{{- end}}
{{- end}}
{{- end}}
Expand Down

0 comments on commit f9955dd

Please sign in to comment.