mirror of
https://github.com/fosrl/newt.git
synced 2026-04-11 20:36:36 +00:00
Switch to scheme
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
|||||||
type HTTPTarget struct {
|
type HTTPTarget struct {
|
||||||
DestAddr string `json:"destAddr"` // IP address or hostname of the downstream service
|
DestAddr string `json:"destAddr"` // IP address or hostname of the downstream service
|
||||||
DestPort uint16 `json:"destPort"` // TCP port of the downstream service
|
DestPort uint16 `json:"destPort"` // TCP port of the downstream service
|
||||||
UseHTTPS bool `json:"useHttps"` // When true the outbound leg uses HTTPS
|
Scheme string `json:"scheme"` // When true the outbound leg uses HTTPS
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -257,10 +257,7 @@ func (h *HTTPHandler) getTLSConfig(rule *SubnetRule) (*tls.Config, error) {
|
|||||||
// creating one on first use. Reusing the proxy preserves its http.Transport
|
// creating one on first use. Reusing the proxy preserves its http.Transport
|
||||||
// connection pool, avoiding repeated TCP/TLS handshakes to the downstream.
|
// connection pool, avoiding repeated TCP/TLS handshakes to the downstream.
|
||||||
func (h *HTTPHandler) getProxy(target HTTPTarget) *httputil.ReverseProxy {
|
func (h *HTTPHandler) getProxy(target HTTPTarget) *httputil.ReverseProxy {
|
||||||
scheme := "http"
|
scheme := target.Scheme
|
||||||
if target.UseHTTPS {
|
|
||||||
scheme = "https"
|
|
||||||
}
|
|
||||||
cacheKey := fmt.Sprintf("%s://%s:%d", scheme, target.DestAddr, target.DestPort)
|
cacheKey := fmt.Sprintf("%s://%s:%d", scheme, target.DestAddr, target.DestPort)
|
||||||
|
|
||||||
if v, ok := h.proxyCache.Load(cacheKey); ok {
|
if v, ok := h.proxyCache.Load(cacheKey); ok {
|
||||||
@@ -273,7 +270,7 @@ func (h *HTTPHandler) getProxy(target HTTPTarget) *httputil.ReverseProxy {
|
|||||||
}
|
}
|
||||||
proxy := httputil.NewSingleHostReverseProxy(targetURL)
|
proxy := httputil.NewSingleHostReverseProxy(targetURL)
|
||||||
|
|
||||||
if target.UseHTTPS {
|
if target.Scheme == "https" {
|
||||||
// Allow self-signed certificates on downstream HTTPS targets.
|
// Allow self-signed certificates on downstream HTTPS targets.
|
||||||
proxy.Transport = &http.Transport{
|
proxy.Transport = &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{
|
TLSClientConfig: &tls.Config{
|
||||||
@@ -307,10 +304,7 @@ func (h *HTTPHandler) handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
target := rule.HTTPTargets[0]
|
target := rule.HTTPTargets[0]
|
||||||
scheme := "http"
|
scheme := target.Scheme
|
||||||
if target.UseHTTPS {
|
|
||||||
scheme = "https"
|
|
||||||
}
|
|
||||||
logger.Info("HTTP handler: %s %s -> %s://%s:%d",
|
logger.Info("HTTP handler: %s %s -> %s://%s:%d",
|
||||||
r.Method, r.URL.RequestURI(), scheme, target.DestAddr, target.DestPort)
|
r.Method, r.URL.RequestURI(), scheme, target.DestAddr, target.DestPort)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user