2020-10-08 10:12:26 +00:00
|
|
|
package connection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2020-10-23 14:49:24 +00:00
|
|
|
"strings"
|
2020-10-08 10:12:26 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
lbProbeUserAgentPrefix = "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/;"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
OriginClient OriginClient
|
|
|
|
GracePeriod time.Duration
|
|
|
|
ReplaceExisting bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type NamedTunnelConfig struct {
|
2020-10-14 10:28:07 +00:00
|
|
|
Auth pogs.TunnelAuth
|
|
|
|
ID uuid.UUID
|
|
|
|
Client pogs.ClientInfo
|
2020-10-08 10:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ClassicTunnelConfig struct {
|
|
|
|
Hostname string
|
|
|
|
OriginCert []byte
|
|
|
|
// feature-flag to use new edge reconnect tokens
|
|
|
|
UseReconnectToken bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClassicTunnelConfig) IsTrialZone() bool {
|
|
|
|
return c.Hostname == ""
|
|
|
|
}
|
|
|
|
|
|
|
|
type OriginClient interface {
|
|
|
|
Proxy(w ResponseWriter, req *http.Request, isWebsocket bool) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResponseWriter interface {
|
|
|
|
WriteRespHeaders(*http.Response) error
|
2020-10-27 22:27:15 +00:00
|
|
|
WriteErrorResponse()
|
2020-10-08 10:12:26 +00:00
|
|
|
io.ReadWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConnectedFuse interface {
|
|
|
|
Connected()
|
|
|
|
IsConnected() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func uint8ToString(input uint8) string {
|
|
|
|
return strconv.FormatUint(uint64(input), 10)
|
|
|
|
}
|
2020-10-23 14:49:24 +00:00
|
|
|
|
|
|
|
func isServerSentEvent(headers http.Header) bool {
|
|
|
|
return strings.ToLower(headers.Get("content-type")) == "text/event-stream"
|
|
|
|
}
|