cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
connection/connection.go
62lines · modecode
| 1 | package connection |
| 2 | |
| 3 | import ( |
| 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 | |
| 14 | const ( |
| 15 | lbProbeUserAgentPrefix = "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/;" |
| 16 | ) |
| 17 | |
| 18 | type Config struct { |
| 19 | OriginClient OriginClient |
| 20 | GracePeriod time.Duration |
| 21 | ReplaceExisting bool |
| 22 | } |
| 23 | |
| 24 | type NamedTunnelConfig struct { |
| 25 | Auth pogs.TunnelAuth |
| 26 | ID uuid.UUID |
| 27 | Client pogs.ClientInfo |
| 28 | } |
| 29 | |
| 30 | type ClassicTunnelConfig struct { |
| 31 | Hostname string |
| 32 | OriginCert []byte |
| 33 | // feature-flag to use new edge reconnect tokens |
| 34 | UseReconnectToken bool |
| 35 | } |
| 36 | |
| 37 | func (c *ClassicTunnelConfig) IsTrialZone() bool { |
| 38 | return c.Hostname == "" |
| 39 | } |
| 40 | |
| 41 | type OriginClient interface { |
| 42 | Proxy(w ResponseWriter, req *http.Request, isWebsocket bool) error |
| 43 | } |
| 44 | |
| 45 | type ResponseWriter interface { |
| 46 | WriteRespHeaders(*http.Response) error |
| 47 | WriteErrorResponse() |
| 48 | io.ReadWriter |
| 49 | } |
| 50 | |
| 51 | type ConnectedFuse interface { |
| 52 | Connected() |
| 53 | IsConnected() bool |
| 54 | } |
| 55 | |
| 56 | func uint8ToString(input uint8) string { |
| 57 | return strconv.FormatUint(uint64(input), 10) |
| 58 | } |
| 59 | |
| 60 | func isServerSentEvent(headers http.Header) bool { |
| 61 | return strings.ToLower(headers.Get("content-type")) == "text/event-stream" |
| 62 | } |
| 63 | |