-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsebel_example_test.go
More file actions
74 lines (60 loc) · 1.59 KB
/
Copy pathsebel_example_test.go
File metadata and controls
74 lines (60 loc) · 1.59 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package sebel_test
import (
"net/http"
"time"
"github.com/teler-sh/sebel"
)
func ExampleNew() {
client := &http.Client{
Transport: sebel.New().RoundTripper(http.DefaultTransport),
}
resp, err := client.Get("https://c2.host")
if err != nil && sebel.IsBlacklist(err) {
// certificate blacklisted
panic(err)
}
defer func() { _ = resp.Body.Close() }()
println("OK")
}
// ExampleNew_autoRefresh demonstrates creating a Sebel instance with automatic
// background SSLBL data refresh.
func ExampleNew_autoRefresh() {
s := sebel.New(sebel.Options{
DataRefreshInterval: 5 * time.Minute,
})
defer s.Close() // Stop background refresh
client := &http.Client{
Transport: s.RoundTripper(http.DefaultTransport),
}
resp, err := client.Get("https://c2.host")
if err != nil && sebel.IsBlacklist(err) {
panic(err)
}
defer func() { _ = resp.Body.Close() }()
}
func ExampleSebel_CheckTLS() {
r, err := http.Get("https://c2.host")
if err != nil {
panic(err)
}
defer func() { _ = r.Body.Close() }()
s := sebel.New()
_, err = s.CheckTLS(r.TLS)
if err != nil && sebel.IsBlacklist(err) {
// certificate blacklisted
panic(err)
}
}
// To seamlessly integrate it without need to configure a new client, you can
// simply replace your current [http.DefaultClient] with sebel's RoundTripper.
func ExampleSebel_RoundTripper() {
http.DefaultClient.Transport = sebel.New().RoundTripper(http.DefaultTransport)
}
func ExampleSebel_CheckHost() {
s := sebel.New()
_, err := s.CheckHost("c2.host", "443", nil)
if err != nil && sebel.IsBlacklist(err) {
// certificate blacklisted
panic(err)
}
}