cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2020.11.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/connection.go

62lines · 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 Auth pogs.TunnelAuth
26 ID uuid.UUID
27 Client pogs.ClientInfo
28}
29
30type ClassicTunnelConfig struct {
31 Hostname string
32 OriginCert []byte
33 // feature-flag to use new edge reconnect tokens
34 UseReconnectToken bool
35}
36
37func (c *ClassicTunnelConfig) IsTrialZone() bool {
38 return c.Hostname == ""
39}
40
41type OriginClient interface {
42 Proxy(w ResponseWriter, req *http.Request, isWebsocket bool) error
43}
44
45type ResponseWriter interface {
46 WriteRespHeaders(*http.Response) error
47 WriteErrorResponse()
48 io.ReadWriter
49}
50
51type ConnectedFuse interface {
52 Connected()
53 IsConnected() bool
54}
55
56func uint8ToString(input uint8) string {
57 return strconv.FormatUint(uint64(input), 10)
58}
59
60func isServerSentEvent(headers http.Header) bool {
61 return strings.ToLower(headers.Get("content-type")) == "text/event-stream"
62}
63