cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ffac598fabae3fa510dce39d05dc497912752de5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

connection/connection.go

77lines · modecode

1package connection
2
3import (
4 "io"
5 "net/http"
6 "strconv"
7 "strings"
8 "time"
9
10 "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
11 "github.com/google/uuid"
12)
13
14const LogFieldConnIndex = "connIndex"
15
16type Config struct {
17 OriginClient OriginClient
18 GracePeriod time.Duration
19 ReplaceExisting bool
20}
21
22type NamedTunnelConfig struct {
23 Credentials Credentials
24 Client pogs.ClientInfo
25}
26
27// Credentials are stored in the credentials file and contain all info needed to run a tunnel.
28type Credentials struct {
29 AccountTag string
30 TunnelSecret []byte
31 TunnelID uuid.UUID
32 TunnelName string
33}
34
35func (c *Credentials) Auth() pogs.TunnelAuth {
36 return pogs.TunnelAuth{
37 AccountTag: c.AccountTag,
38 TunnelSecret: c.TunnelSecret,
39 }
40}
41
42type ClassicTunnelConfig struct {
43 Hostname string
44 OriginCert []byte
45 // feature-flag to use new edge reconnect tokens
46 UseReconnectToken bool
47}
48
49func (c *ClassicTunnelConfig) IsTrialZone() bool {
50 return c.Hostname == ""
51}
52
53type OriginClient interface {
54 Proxy(w ResponseWriter, req *http.Request, isWebsocket bool) error
55}
56
57type ResponseWriter interface {
58 WriteRespHeaders(*http.Response) error
59 WriteErrorResponse()
60 io.ReadWriter
61}
62
63type ConnectedFuse interface {
64 Connected()
65 IsConnected() bool
66}
67
68func IsServerSentEvent(headers http.Header) bool {
69 if contentType := headers.Get("content-type"); contentType != "" {
70 return strings.HasPrefix(strings.ToLower(contentType), "text/event-stream")
71 }
72 return false
73}
74
75func uint8ToString(input uint8) string {
76 return strconv.FormatUint(uint64(input), 10)
77}
78