This repository has been archived by the owner on Mar 19, 2023. It is now read-only.
/
httptls.go
52 lines (45 loc) · 1.45 KB
/
httptls.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 dslx
//
// TLS adapters for HTTP
//
import (
"context"
"github.com/bassosimone/oonidsl/internal/netxlite"
)
// HTTPRequestOverTLS returns a Func that issues HTTP requests over TLS.
func HTTPRequestOverTLS(options ...HTTPRequestOption) Func[*TLSConnection, *Maybe[*HTTPResponse]] {
return Compose2(HTTPTransportTLS(), HTTPRequest(options...))
}
// HTTPTransportTLS converts a TLS connection into an HTTP transport.
func HTTPTransportTLS() Func[*TLSConnection, *Maybe[*HTTPTransport]] {
return &httpTransportTLSFunc{}
}
// httpTransportTLSFunc is the function returned by HTTPTransportTLS.
type httpTransportTLSFunc struct{}
// Apply implements Func.
func (f *httpTransportTLSFunc) Apply(
ctx context.Context, input *TLSConnection) *Maybe[*HTTPTransport] {
httpTransport := netxlite.NewHTTPTransport(
input.Logger,
netxlite.NewNullDialer(),
netxlite.NewSingleUseTLSDialer(input.Conn),
)
state := &HTTPTransport{
Address: input.Address,
Domain: input.Domain,
IDGenerator: input.IDGenerator,
Logger: input.Logger,
Network: input.Network,
Scheme: "https",
TLSNegotiatedProtocol: input.TLSState.NegotiatedProtocol,
Trace: input.Trace,
Transport: httpTransport,
ZeroTime: input.ZeroTime,
}
return &Maybe[*HTTPTransport]{
Error: nil,
Observations: nil,
Skipped: false,
State: state,
}
}