-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.go
52 lines (45 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
oohttp "github.com/ooni/oohttp"
"github.com/ooni/oohttp/example/internal/utlsx"
)
// newTransport returns a new http.Transport using the provided tls dialer.
func newTransport(f func(ctx context.Context, network, address string) (net.Conn, error)) http.RoundTripper {
return utlsx.NewOOHTTPTransport(
oohttp.ProxyFromEnvironment,
nil, // we're using f to directly create TLS connections
f,
)
}
// defaultTransport is the default http.RoundTripper.
var defaultTransport = newTransport((&utlsx.TLSDialer{}).DialTLSContext)
// newClient creates a new http.Client using the given transport.
func newClient(txp http.RoundTripper) *http.Client {
return &http.Client{Transport: txp}
}
// defaultClient is the default http.Client
var defaultClient = newClient(defaultTransport)
func main() {
// The default URL we use should return us the JA3 fingerprint
// we're using to communicate with the server. We expect such a
// fingerprint to change when we use the `-utls` flag.
url := flag.String("url", "https://ja3er.com/json", "the URL to get")
flag.Parse()
resp, err := defaultClient.Get(*url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", data)
}