Location first attempt

This commit is contained in:
regnaio 2022-03-29 06:31:52 -04:00
parent c0f85ab85b
commit 901fd63c97
4 changed files with 14 additions and 0 deletions

View File

@ -180,6 +180,7 @@ type UnvalidatedIngressRule struct {
Hostname string `json:"hostname"`
Path string `json:"path"`
Service string `json:"service"`
Location string `json:"location"`
OriginRequest OriginRequestConfig `yaml:"originRequest" json:"originRequest"`
}

View File

@ -244,6 +244,7 @@ func validateIngress(ingress []config.UnvalidatedIngressRule, defaults OriginReq
Hostname: r.Hostname,
Service: service,
Path: pathRegexp,
Location: r.Location,
Config: cfg,
}
}

View File

@ -20,6 +20,9 @@ type Rule struct {
// address.
Service OriginService `json:"service"`
// Location is an optional string that can specify the Service path (overwriting the Hostname path).
Location string `json:"location"`
// Configure the request cloudflared sends to this specific origin.
Config OriginRequestConfig `json:"originRequest"`
}

View File

@ -7,6 +7,7 @@ import (
"io"
"net/http"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/rs/zerolog"
@ -78,6 +79,14 @@ func (p *Proxy) ProxyHTTP(
}
p.logRequest(req, logFields)
fmt.Println(fmt.Sprintf("before: req.URL.Path: %s", req.URL.Path))
parts := strings.Split(req.URL.Path, "/")
if len(parts) > 0 {
parts[0] = rule.Location
}
req.URL.Path = strings.Join(parts, "/")
fmt.Println(fmt.Sprintf("after: req.URL.Path: %s", req.URL.Path))
switch originProxy := rule.Service.(type) {
case ingress.HTTPOriginProxy:
if err := p.proxyHTTPRequest(