cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2020.11.10

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/connection.go

65lines · 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 IsServerSentEvent(headers http.Header) bool {
57 if contentType := headers.Get("content-type"); contentType != "" {
58 return strings.HasPrefix(strings.ToLower(contentType), "text/event-stream")
59 }
60 return false
61}
62
63func uint8ToString(input uint8) string {
64 return strconv.FormatUint(uint64(input), 10)
65}
66