-
Notifications
You must be signed in to change notification settings - Fork 6
/
http.go
29 lines (26 loc) · 760 Bytes
/
http.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
package dane
import (
"context"
"net"
"net/http"
"strconv"
"strings"
)
//
// GetHttpClient returns a net/http Client structure configured to perform
// DANE TLS authentication of the HTTPS server. If the argument pkixfallback
// is set to true, then PKIX authentication will be attempted if the server
// does not have any published secure DANE TLSA records.
//
func GetHttpClient(pkixfallback bool) http.Client {
t := &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
tmp := strings.SplitN(addr, ":", 2)
hostname := tmp[0]
port, _ := strconv.Atoi(tmp[1])
conn, _, err := ConnectByNameAsync2(hostname, port, pkixfallback)
return conn, err
},
}
return http.Client{Transport: t}
}