-
Notifications
You must be signed in to change notification settings - Fork 1
/
tls.go
49 lines (39 loc) · 898 Bytes
/
tls.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
package vhttp
import (
"crypto/tls"
"fmt"
"net/http"
)
// TLSValidator is a validator that validates an http.Request or http.Response
// object's TLS connection.
type TLSValidator func(*tls.ConnectionState) error
func (v TLSValidator) ValidateRequest(req *http.Request) error {
return v(req.TLS)
}
func (v TLSValidator) ValidateResponse(res *http.Response) error {
return v(res.TLS)
}
func TLSIsNil() TLSValidator {
return func(tls *tls.ConnectionState) error {
if tls != nil {
return fmt.Errorf("tls is not nil")
}
return nil
}
}
func TLSIsNotNil() TLSValidator {
return func(tls *tls.ConnectionState) error {
if tls != nil {
return fmt.Errorf("tls is nil")
}
return nil
}
}
func TLSVersionIs(v uint16) TLSValidator {
return func(tls *tls.ConnectionState) error {
if tls.Version != v {
return fmt.Errorf("tls version is not %d", v)
}
return nil
}
}