cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2ea491b1d07d3ea6678cda82656f06d5205ec007

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/connection.go

79lines · 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 (
15 lbProbeUserAgentPrefix = "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/;"
16)
17
18type Config struct {
19 OriginClient OriginClient
20 GracePeriod time.Duration
21 ReplaceExisting bool
22}
23
24type NamedTunnelConfig struct {
25 Credentials Credentials
26 Client pogs.ClientInfo
27}
28
29// Credentials are stored in the credentials file and contain all info needed to run a tunnel.
30type Credentials struct {
31 AccountTag string
32 TunnelSecret []byte
33 TunnelID uuid.UUID
34 TunnelName string
35}
36
37func (c *Credentials) Auth() pogs.TunnelAuth {
38 return pogs.TunnelAuth{
39 AccountTag: c.AccountTag,
40 TunnelSecret: c.TunnelSecret,
41 }
42}
43
44type ClassicTunnelConfig struct {
45 Hostname string
46 OriginCert []byte
47 // feature-flag to use new edge reconnect tokens
48 UseReconnectToken bool
49}
50
51func (c *ClassicTunnelConfig) IsTrialZone() bool {
52 return c.Hostname == ""
53}
54
55type OriginClient interface {
56 Proxy(w ResponseWriter, req *http.Request, isWebsocket bool) error
57}
58
59type ResponseWriter interface {
60 WriteRespHeaders(*http.Response) error
61 WriteErrorResponse()
62 io.ReadWriter
63}
64
65type ConnectedFuse interface {
66 Connected()
67 IsConnected() bool
68}
69
70func IsServerSentEvent(headers http.Header) bool {
71 if contentType := headers.Get("content-type"); contentType != "" {
72 return strings.HasPrefix(strings.ToLower(contentType), "text/event-stream")
73 }
74 return false
75}
76
77func uint8ToString(input uint8) string {
78 return strconv.FormatUint(uint64(input), 10)
79}
80