/
spec.go
53 lines (39 loc) 路 1.05 KB
/
spec.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
package relay
import (
"net/http"
"github.com/btwiuse/muxr"
"github.com/webteleport/webteleport/edge"
)
// dispatch to other http.Handler implementations
type Dispatcher interface {
Dispatch(r *http.Request) http.Handler
}
// wrapping Dispatcher into http.Handler
type DispatcherFunc func(*http.Request) http.Handler
func (d DispatcherFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
d(r).ServeHTTP(w, r)
}
// edge.Edge multiplexer with builtin HTTPUpgrader
type Relayer interface {
// dispatch to HTTPUpgrader and Storage
Dispatcher
// builtin HTTPUpgrader
edge.HTTPUpgrader
// edge.Edge multiplexer
Storage
}
// edge.Edge multiplexer
type Storage interface {
// Dispatch to edge.Edge
Dispatcher
// get Session wrapped by http.Transport
GetRoundTripper(k string) (http.RoundTripper, bool)
// record Info
RecordsHandler(w http.ResponseWriter, r *http.Request)
// subscribe to incoming stream of edge.Edge
edge.Subscriber
// apply middleware to dispatcher
Use(middlewares ...muxr.Middleware)
// shortcut to dispatcher
http.Handler
}