-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirect.go
58 lines (49 loc) · 1.21 KB
/
direct.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
53
54
55
56
57
58
// Froxy - HTTP over SSH proxy
//
// Copyright (C) 2019 and up by Alexander Pevzner (pzz@apevzner.com)
// See LICENSE for license terms and conditions
//
// Direct (non-relayed) transport
package main
import (
"context"
"net"
"net/http"
)
//
// Transport that connects directly
//
type DirectTransport struct {
http.Transport // Direct http.Transport
froxy *Froxy // Back link to Froxy
}
//
// Create new DirectTransport
//
func NewDirectTransport(froxy *Froxy) *DirectTransport {
t := &DirectTransport{
Transport: http.Transport{
Proxy: nil,
MaxIdleConns: HTTP_MAX_IDLE_CONNS,
IdleConnTimeout: HTTP_IDLE_CONN_TIMEOUT,
ExpectContinueTimeout: HTTP_EXPECT_CONTINUE_TIMEOUT,
},
froxy: froxy,
}
t.Transport.DialContext = t.DialContext
return t
}
//
// Dial new TCP connection
//
func (t *DirectTransport) Dial(network, addr string) (net.Conn, error) {
return t.DialContext(context.Background(), network, addr)
}
//
// Dial new TCP connection with context
//
func (t *DirectTransport) DialContext(ctx context.Context,
network, addr string) (net.Conn, error) {
return t.froxy.connMan.DialContext(ctx, network, addr,
&t.froxy.Counters.TCPConnections)
}