-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
81 lines (69 loc) · 2.5 KB
/
options.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package ttyd
import (
"time"
"github.com/gobwas/ws/wsflate"
)
// A HandlerOption sets an option on a handler.
type HandlerOption func(*Handler)
// EnableCompressionWithContextTakeover enables compression with context takeover.
func EnableCompressionWithContextTakeover() HandlerOption {
return EnableCompressionWithExtension(&wsflate.Extension{})
}
// EnableCompressionWithNoContextTakeover enables compression with no context takeover.
func EnableCompressionWithNoContextTakeover() HandlerOption {
return EnableCompressionWithExtension(&wsflate.Extension{
Parameters: wsflate.Parameters{
ServerNoContextTakeover: true,
ClientNoContextTakeover: true,
},
})
}
// EnableCompressionWithExtension enables compression with the specified extension.
func EnableCompressionWithExtension(extension *wsflate.Extension) HandlerOption {
return func(h *Handler) {
h.extension = extension
}
}
// EnableClientInput enables client inputs to the tty.
func EnableClientInput() HandlerOption {
return func(h *Handler) {
h.writable = true
}
}
// WithClientOptions sets the client options to be sent to the client.
// These options can also be set by the client using the URL query parameters,
// and they have a higher priority than these options.
// Caller should make sure the options can be serialized to JSON.
func WithClientOptions(options map[string]any) HandlerOption {
return func(h *Handler) {
h.options = options
}
}
// WithMessageSizeLimit sets the maximum size of messages that can be sent to the server.
// Zero or negative value means no limit.
func WithMessageSizeLimit(limit int64) HandlerOption {
return func(h *Handler) {
h.messageSizeLimit = limit
}
}
// WithCompressionLevel sets the compression level for the flate writer if compression is negotiated with the peer.
// Invalid levels or NoCompression will be treated as default compression level.
func WithCompressionLevel(level int) HandlerOption {
return func(h *Handler) {
h.compressionLevel = level
}
}
// WithTitle sets the title of the terminal. By default, the title is set to the command being run joined with the hostname.
func WithTitle(title string) HandlerOption {
return func(h *Handler) {
h.title = title
}
}
// WithPingInterval sets the interval at which ping frames are sent to clients.
// Zero or negative value disables the sending of pings. It's used to keep the connection alive when ttyd
// is used over a proxy.
func WithPingInterval(interval time.Duration) HandlerOption {
return func(h *Handler) {
h.pingInterval = interval
}
}