Skip to content

Commit 21b198c

Browse files
committed
egress uma missing model package fix
1 parent 512e96a commit 21b198c

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package model
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
"strings"
8+
"time"
9+
)
10+
11+
var HttpClient = &http.Client{
12+
Transport: &localRedirectTransport{
13+
rt: http.DefaultTransport,
14+
},
15+
Timeout: 5 * time.Second,
16+
}
17+
18+
// localRedirectTransport rewrites requests to localhost -> host.docker.internal
19+
type localRedirectTransport struct {
20+
rt http.RoundTripper
21+
}
22+
23+
func (t *localRedirectTransport) RoundTrip(req *http.Request) (*http.Response, error) {
24+
// Rewrite localhost hostnames
25+
if strings.HasPrefix(req.URL.Host, "localhost") || strings.HasPrefix(req.URL.Host, "127.0.0.1") {
26+
// Keep the port if present
27+
host, port, _ := net.SplitHostPort(req.URL.Host)
28+
if host == "" {
29+
host = req.URL.Host
30+
}
31+
if port != "" {
32+
req.URL.Host = fmt.Sprintf("host.docker.internal:%s", port)
33+
} else {
34+
req.URL.Host = "host.docker.internal"
35+
}
36+
}
37+
38+
// Optional: update the Host header so server sees correct host
39+
if req.Host == "" || req.Host == "localhost" || req.Host == "127.0.0.1" {
40+
req.Host = strings.Split(req.URL.Host, ":")[0]
41+
}
42+
43+
return t.rt.RoundTrip(req)
44+
}

containers/egress-uma/uma.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"egress-uma/model"
56
"encoding/json"
67
"errors"
78
"io"

0 commit comments

Comments
 (0)