This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transport.go
66 lines (52 loc) · 1.84 KB
/
transport.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
59
60
61
62
63
64
65
66
package fasthttp
import (
"crypto/tls"
"log"
"net/url"
"time"
"github.com/fasthttp/websocket"
"github.com/qbeon/webwire-go"
"github.com/valyala/fasthttp"
)
// TLS represents TLS configuration
type TLS struct {
CertFilePath string
PrivateKeyFilePath string
Config *tls.Config
}
// Transport implements the webwire transport layer with fasthttp
type Transport struct {
// Host defines the address of the host
Host string
// OnOptions is invoked when the websocket endpoint is examined by the
// client using the HTTP OPTION method.
OnOptions func(*fasthttp.RequestCtx)
// BeforeUpgrade is invoked right before the upgrade of the connection of an
// incoming HTTP request to a WebSocket connection and can be used to
// intercept, configure or prevent incoming connections. BeforeUpgrade must
// return the connection options to be applied or set options.Connection to
// webwire.Refuse to refuse the incoming connection
BeforeUpgrade func(ctx *fasthttp.RequestCtx) webwire.ConnectionOptions
// WarnLog defines the warn logging output target
WarnLog *log.Logger
// ErrorLog defines the error logging output target
ErrorLog *log.Logger
// KeepAlive enables the keep-alive option if set to a duration above -1.
// KeepAlive is automatically set to 30 seconds when it's set to 0
KeepAlive time.Duration
// Upgrader specifies the websocket connection upgrader
Upgrader *websocket.FastHTTPUpgrader
// HTTPServer specifies the FastHTTP server
HTTPServer *fasthttp.Server
// TLS enables TLS encryption if specified
TLS *TLS
listener *tcpKeepAliveListener
addr url.URL
readTimeout time.Duration
isShuttingdown webwire.IsShuttingDown
onNewConnection webwire.OnNewConnection
}
// Address returns the URL address the server is listening on
func (srv *Transport) Address() url.URL {
return srv.addr
}