Files
zeekay 285bb5a76b rename: ziti → zt across all paths
- Repo names: ziti-* → zt-*
- Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt
- Docker images: hanzozt/ziti-* → hanzozt/zt-*
- C/Java/JS symbols: ziti_* → zt_*
- File and directory names updated
2026-02-18 18:34:10 -08:00

46 lines
1.0 KiB
Go

package main
import (
"context"
"github.com/hanzozt/sdk-golang/zt"
"io"
"net"
"net/http"
"os"
)
func newZitiClient() *http.Client {
zt.DefaultCollection.ForAll(func(ctx zt.Context) {
ctx.Authenticate()
})
ztTransport := http.DefaultTransport.(*http.Transport).Clone() // copy default transport
ztTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := zt.DefaultCollection.NewDialer()
return dialer.Dial(network, addr)
}
ztTransport.TLSClientConfig.InsecureSkipVerify = true
return &http.Client{Transport: ztTransport}
}
// this is a clone of ../curlz but showing the use of zt.Dialer
// identities are loaded from ZITI_IDENTITIES environment variable -- ';'-separated list of identity files
//
// saple usage:
// ```
//
// $ export ZITI_IDENTITIES=<path to id file>
// $ http-client http://<intercepted address>/path
//
// ```
func main() {
resp, err := newZitiClient().Get(os.Args[1])
if err != nil {
panic(err)
}
_, err = io.Copy(os.Stdout, resp.Body)
if err != nil {
panic(err)
}
}