Skip to content

Commit 9338c48

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: add scheme support in HTTP(S) redirects
1 parent 65e37ee commit 9338c48

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/annotations/ingress/hostRedirect.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ package ingress
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67

78
"github.com/haproxytech/kubernetes-ingress/pkg/annotations/common"
89
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/rules"
910
"github.com/haproxytech/kubernetes-ingress/pkg/store"
1011
)
1112

13+
//nolint:golint,stylecheck
14+
const (
15+
HTTP_PREFIX = "http://"
16+
HTTPS_PREFIX = "https://"
17+
)
18+
1219
type HostRedirect struct {
1320
redirect *rules.RequestRedirect
1421
rules *rules.List
@@ -43,6 +50,14 @@ func (a HostRedirectAnn) Process(k store.K8s, annotations ...map[string]string)
4350
switch a.name {
4451
case "request-redirect":
4552
a.parent.redirect = &rules.RequestRedirect{Host: input}
53+
switch {
54+
case strings.HasPrefix(input, HTTPS_PREFIX):
55+
a.parent.redirect.SSLRequest = true
56+
a.parent.redirect.Host = a.parent.redirect.Host[len(HTTPS_PREFIX):]
57+
case strings.HasPrefix(input, HTTP_PREFIX):
58+
a.parent.redirect.SSLRequest = false
59+
a.parent.redirect.Host = a.parent.redirect.Host[len(HTTP_PREFIX):]
60+
}
4661
a.parent.rules.Add(a.parent.redirect)
4762
return
4863
case "request-redirect-code":

0 commit comments

Comments
 (0)