HTTP reverse proxy for Tailscale

sort targets in disco endpoint

+5 -3
+1 -1
main.go
··· 251 251 // SingleHostReverseProxy for each upstream. 252 252 rpx = make(map[string]http.Handler) 253 253 254 - // targets returned by http_sd discovery endpoint. 254 + // targets returned by the http_sd discovery endpoint. 255 255 targets []string 256 256 ) 257 257 for _, u := range ups {
+2
tsproxy.go
··· 7 7 "net/http" 8 8 "net/http/httputil" 9 9 "net/url" 10 + "sort" 10 11 11 12 "golang.org/x/exp/slog" 12 13 "tailscale.com/client/tailscale/apitype" ··· 46 47 } 47 48 48 49 func tsReverseProxy(rpx map[string]http.Handler, metrics http.Handler, targets []string, self string) http.Handler { 50 + sort.Strings(targets) 49 51 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 50 52 if r.TLS == nil { 51 53 http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
+2 -2
tsproxy_test.go
··· 145 145 }, 146 146 { 147 147 name: "self service discovery", 148 - h: tsReverseProxy(nil, nil, []string{"localhost:8000"}, "example.com"), 148 + h: tsReverseProxy(nil, nil, []string{"zzz:80", "localhost:8000"}, "example.com"), 149 149 req: &http.Request{RequestURI: "/sd", TLS: &tls.ConnectionState{ServerName: "example.com"}}, 150 - want: &http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{`application/json; charset=utf-8`}}, Body: io.NopCloser(bytes.NewReader([]byte(`[{"targets":["localhost:8000"]}]`)))}, 150 + want: &http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{`application/json; charset=utf-8`}}, Body: io.NopCloser(bytes.NewReader([]byte(`[{"targets":["localhost:8000","zzz:80"]}]`)))}, 151 151 }, 152 152 } { 153 153 tc := tc