diff --git a/pkg/router/router.go b/pkg/router/router.go index efac620..bd0b9d3 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -70,6 +70,7 @@ func (r *RoutingTable) GetBackend(host, uri, ip string) (*url.URL, map[string]st path.Backend.Service.Name, path.Backend.Service.Port.Number, ), + Path: path.Path, Scheme: "http", }, ingress.Annotations, RoutingError{} } @@ -98,6 +99,7 @@ func (r *RoutingTable) GetBackend(host, uri, ip string) (*url.URL, map[string]st path.Backend.Service.Name, path.Backend.Service.Port.Number, ), + Path: path.Path, Scheme: "http", }, ingress.Annotations, RoutingError{} } diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index b158c0e..6c368be 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -2,6 +2,7 @@ package router import ( "crypto/tls" + "fmt" "github.com/h3adex/guardgress/pkg/mocks" "github.com/stretchr/testify/assert" "github.com/ulule/limiter/v3" @@ -264,3 +265,28 @@ func TestGetBackendWithMultipleIngresses(t *testing.T) { assert.NoError(t, err.Error) assert.Equal(t, url.Host, "127.0.0.1:20100") } + +func TestCertManagerImplementation(t *testing.T) { + mock := mocks.IngressPathTypeImplementationSpecificTypeMock() + mock.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Port.Number = 8089 + mock.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name = "cm-acme-http-solver-mqvwg" + mock.Spec.Rules[0].HTTP.Paths[0].Path = "/.well-known/acme-challenge/5XSJIlrUE9OZl_Og7-Y--vIM2eeGhnvSXJLSejioqcM" + + routingTable := RoutingTable{ + Ingresses: &v1.IngressList{ + TypeMeta: v12.TypeMeta{}, + ListMeta: v12.ListMeta{}, + Items: []v1.Ingress{ + mock, + }, + }, + TlsCertificates: mocks.TlsCertificatesMock(), + IngressLimiters: []*limiter.Limiter{nil}, + } + + // should work with path type implementation specific + url, _, err := routingTable.GetBackend("www.guardgress.com", "/.well-known/acme-challenge/5XSJIlrUE9OZl_Og7-Y--vIM2eeGhnvSXJLSejioqcM", "127.0.0.1") + assert.NoError(t, err.Error) + assert.Equal(t, mock.Spec.Rules[0].HTTP.Paths[0].Path, url.Path) + assert.Equal(t, fmt.Sprintf("%s:%d", mock.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name, mock.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Port.Number), url.Host) +} diff --git a/pkg/server/server.go b/pkg/server/server.go index 7aef8ed..41d89bf 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/caarlos0/env" "github.com/gin-gonic/gin" + "github.com/gospider007/net/http2" "github.com/h3adex/fp" "github.com/h3adex/guardgress/pkg/algorithms" "github.com/h3adex/guardgress/pkg/annotations" @@ -141,6 +142,13 @@ func (s Server) ServeHttps(ctx *gin.Context) { log.Debug("proxying https request to: ", svcUrl) proxy := httputil.NewSingleHostReverseProxy(svcUrl) + + if svcUrl.Scheme == "https" { + proxy.Transport = &http2.Transport{ + AllowHTTP: true, + } + } + proxy.Director = func(req *http.Request) { req.Header = ctx.Request.Header req.Host = svcUrl.Host @@ -173,6 +181,13 @@ func (s Server) ServeHTTP(ctx *gin.Context) { log.Debug("proxying http request to: ", svcUrl) proxy := httputil.NewSingleHostReverseProxy(svcUrl) + + if svcUrl.Scheme == "https" { + proxy.Transport = &http2.Transport{ + AllowHTTP: true, + } + } + proxy.Director = func(req *http.Request) { req.Header = ctx.Request.Header req.Host = svcUrl.Host