mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-23 22:17:14 +02:00
integration: add cluster setup and configuration and a few tests
This commit is contained in:
parent
9860c3ce9f
commit
8fd716e1d8
24 changed files with 1689 additions and 2 deletions
44
integration/internal/httputil/httputil.go
Normal file
44
integration/internal/httputil/httputil.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type localRoundTripper struct {
|
||||
underlying http.RoundTripper
|
||||
portToAddr map[string]string
|
||||
}
|
||||
|
||||
func NewLocalRoundTripper(underlying http.RoundTripper, portToAddr map[string]string) http.RoundTripper {
|
||||
lrt := &localRoundTripper{underlying: underlying, portToAddr: portToAddr}
|
||||
return lrt
|
||||
}
|
||||
|
||||
func (lrt *localRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
req = req.Clone(req.Context())
|
||||
req.URL.Host = lrt.remapHost(req.Context(), req.Host)
|
||||
return lrt.underlying.RoundTrip(req)
|
||||
}
|
||||
|
||||
func (lrt *localRoundTripper) remapHost(ctx context.Context, hostport string) string {
|
||||
host, port, err := net.SplitHostPort(hostport)
|
||||
if err != nil {
|
||||
host = hostport
|
||||
port = "443"
|
||||
}
|
||||
|
||||
dst, ok := lrt.portToAddr[port]
|
||||
if !ok {
|
||||
return hostport
|
||||
}
|
||||
|
||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, host)
|
||||
if err != nil || len(ips) == 0 || ips[0].String() != "127.0.0.1" {
|
||||
return hostport
|
||||
}
|
||||
|
||||
return dst
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue