Skip to content

Commit 3e22bcf

Browse files
Merge pull request #816 from vincentmli/vli-PR
http_redirect_irule_443 irule should honor custom http port
2 parents 525894a + 2ab80a2 commit 3e22bcf

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pkg/appmanager/resourceConfig.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,9 @@ func (appMgr *Manager) createRSConfigFromIngress(
15681568
}
15691569
cfg.MetaData.ingName = ing.ObjectMeta.Name
15701570

1571+
sslRedirect := getBooleanAnnotation(ing.ObjectMeta.Annotations,
1572+
ingressSslRedirect, true)
1573+
15711574
resources.Lock()
15721575
defer resources.Unlock()
15731576
// Check to see if we already have any Ingresses for this IP:Port
@@ -1614,7 +1617,7 @@ func (appMgr *Manager) createRSConfigFromIngress(
16141617
}
16151618
}
16161619
} else if len(cfg.Policies) == 0 && plcy != nil {
1617-
cfg.SetPolicy(*plcy)
1620+
cfg.IngSetPolicy(*plcy, sslRedirect, pStruct.protocol)
16181621
}
16191622
} else { // This is a new VS for an Ingress
16201623
cfg.MetaData.ResourceType = "ingress"
@@ -1624,7 +1627,7 @@ func (appMgr *Manager) createRSConfigFromIngress(
16241627
cfg.Virtual.SetVirtualAddress(bindAddr, pStruct.port)
16251628
cfg.Pools = append(cfg.Pools, pools...)
16261629
if plcy != nil {
1627-
cfg.SetPolicy(*plcy)
1630+
cfg.IngSetPolicy(*plcy, sslRedirect, pStruct.protocol)
16281631
}
16291632
}
16301633

@@ -2204,6 +2207,36 @@ func (rc *ResourceConfig) SetPolicy(policy Policy) {
22042207
rc.Policies = append(rc.Policies, policy)
22052208
}
22062209

2210+
func (rc *ResourceConfig) IngSetPolicy(policy Policy, sslRedirect bool, pProtocol string) {
2211+
toFind := nameRef{
2212+
Name: policy.Name,
2213+
Partition: policy.Partition,
2214+
}
2215+
found := false
2216+
for _, polName := range rc.Virtual.Policies {
2217+
if reflect.DeepEqual(toFind, polName) {
2218+
found = true
2219+
break
2220+
}
2221+
}
2222+
if !found {
2223+
if sslRedirect {
2224+
if pProtocol == "https" {
2225+
rc.Virtual.Policies = append(rc.Virtual.Policies, toFind)
2226+
}
2227+
} else {
2228+
rc.Virtual.Policies = append(rc.Virtual.Policies, toFind)
2229+
}
2230+
}
2231+
for i, pol := range rc.Policies {
2232+
if pol.Name == policy.Name && pol.Partition == policy.Partition {
2233+
rc.Policies[i] = policy
2234+
return
2235+
}
2236+
}
2237+
rc.Policies = append(rc.Policies, policy)
2238+
}
2239+
22072240
func (rc *ResourceConfig) RemovePolicy(policy Policy) {
22082241
toFind := nameRef{
22092242
Name: policy.Name,

pkg/appmanager/routing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func httpRedirectIRule(port int32) string {
350350
iRuleCode := fmt.Sprintf(`
351351
when HTTP_REQUEST {
352352
# Look for exact match for host name
353-
set paths [class match -value [HTTP::host] equals https_redirect_dg]
353+
set paths [class match -value [getfield [HTTP::host] ":" 1] equals https_redirect_dg]
354354
if {$paths == ""} {
355355
# See if there's an entry that matches all hosts
356356
set paths [class match -value "*" equals https_redirect_dg]

0 commit comments

Comments
 (0)