Documentation ¶
Overview ¶
Package jar is a readily-embeddable feature-rich proxy-focused AWS-aware distributed-oriented resiliency-enabling URL-driven superlative-laced ***elastic application link***. At its core, JAR is "just" a load-balancing proxy taking cues from HAProxy (resiliency, zero-drop restarts, performance) and Apache HTTPD (virtualize everything) while leveraging over 20 years of systems engineering experience to provide robust features with exceptional stability.
JAR has been in production use since 2018 and handles millions of connections a day across heterogeneous application stacks.
Consumers will want to 'cd cmd/jard; go build; #enjoy'
Index ¶
- Constants
- Variables
- func AccessLogHandler(next http.Handler) http.Handler
- func AddMetrics(m map[string]map[string]interface{}, hc *health.Check) *health.Check
- func AddStatuses(s *health.StatusRegistry, hc *health.Check) *health.Check
- func AuthoritativeDomainsHandler(next http.Handler) http.Handler
- func Bootstrap()
- func BootstrapChan(closer chan struct{})
- func BuildPath(path *Path, index int, router *mux.Router) (int, error)
- func BuildPaths(router *mux.Router) error
- func ChanBootstrap() chan error
- func ConnectionCounterAdd()
- func ConnectionCounterGet() int64
- func ConnectionCounterRemove()
- func CopyHeaders(dst http.Header, src http.Header)
- func CopyRequest(req *http.Request) *http.Request
- func CopyURL(i *url.URL) *url.URL
- func DateFinisher(w http.ResponseWriter, r *http.Request)
- func DumpFinisher(w http.ResponseWriter, r *http.Request)
- func DumpHandler(h http.Handler) http.Handler
- func ECBDecrypt(b64key string, eb64ciphertext string) (plaintext []byte, err error)
- func ECBEncrypt(b64key string, plaintext []byte) (b64ciphertext string, err error)
- func EndpointDecider(w http.ResponseWriter, r *http.Request)
- func FileExists(filePath string) bool
- func FlashEncoding(src string) string
- func FolderExists(filePath string) bool
- func Forbidden(w http.ResponseWriter, r *http.Request)
- func GetErrorLog(filename, prefix string, format, size, backups, age int) *log.Logger
- func GetLog(filename, prefix string, format, size, backups, age int) *log.Logger
- func GetLogOrDiscard(filename, prefix string, format, size, backups, age int) *log.Logger
- func GetRequestID(ctx context.Context) string
- func GetSwitchName(request *http.Request) string
- func HandleFinisher(handler string, path *Path) (http.HandlerFunc, error)
- func HandleGenericWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
- func HandleHandler(handler string, hchain alice.Chain) (alice.Chain, error)
- func HandleReload(name string, mfiles map[string]string)
- func HandleRemoteWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
- func HandleTemplateWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
- func InitConfig() *viper.Viper
- func LoadConfig(configFilename string, v *viper.Viper) error
- func LogInit() error
- func MinuteDelayer(w http.ResponseWriter, r *http.Request)
- func MinuteStreamer(w http.ResponseWriter, r *http.Request)
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func NewStickyPool(poolName, cookieName, cookieType string, next http.Handler, ...) (*roundrobin.RoundRobin, error)
- func OkFinisher(w http.ResponseWriter, r *http.Request)
- func PoolLister(w http.ResponseWriter, r *http.Request)
- func PoolMemberAdder(w http.ResponseWriter, r *http.Request)
- func PoolMemberLister(w http.ResponseWriter, r *http.Request)
- func PoolMemberLoser(w http.ResponseWriter, r *http.Request)
- func PrettyPrint(v interface{}) string
- func ReaderToString(r io.Reader) string
- func RealAddr(h http.Handler) http.Handler
- func Recoverer(next http.Handler) http.Handler
- func ReplaceURI(r *http.Request, urlPath, requestURI string)
- func RequestErrorResponse(r *http.Request, w http.ResponseWriter, Message string, code int)
- func RequestErrorString(Request *http.Request, Message string) string
- func RequestIDFinisher(w http.ResponseWriter, r *http.Request)
- func ResponseHeaders(next http.Handler) http.Handler
- func Restart(w http.ResponseWriter, r *http.Request)
- func RouteIDInspectionHandler(next http.Handler) http.Handler
- func S3StreamProxyFinisher(w http.ResponseWriter, r *http.Request)
- func SetupHandler(next http.Handler) http.Handler
- func Stack(w http.ResponseWriter, r *http.Request)
- func StringIfCtx(r *http.Request, name interface{}) string
- func StringToCleanList(in, sep string) []string
- func SwitchHandler(next http.Handler) http.Handler
- func TestFinisher(w http.ResponseWriter, r *http.Request)
- func TrimPrefixURI(r *http.Request, prefix string)
- func URLCaptureHandler(next http.Handler) http.Handler
- func Unzip(src, dest string) error
- func Update(w http.ResponseWriter, r *http.Request)
- func ValidateExtras() []error
- func WithRqID(ctx context.Context, requestID string) context.Context
- func WithSessionID(ctx context.Context, sessionID string) context.Context
- type Access
- type AccessLog
- type BasicAuth
- type BodyByteLimit
- type CORS
- type CacheCluster
- type Cert
- type Compression
- type ConfigKey
- type ConsistentHashPool
- func (ch *ConsistentHashPool) Next() http.Handler
- func (ch *ConsistentHashPool) NextServer() (*url.URL, error)
- func (ch *ConsistentHashPool) RemoveServer(u *url.URL) error
- func (ch *ConsistentHashPool) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ch *ConsistentHashPool) ServerWeight(u *url.URL) (int, bool)
- func (ch *ConsistentHashPool) Servers() []*url.URL
- func (ch *ConsistentHashPool) UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error
- type CorsString
- type DebugTrip
- type ErrConfigurationError
- type ErrRequestError
- type Error
- type ErrorWrapper
- type FinisherMap
- type FinisherSetupFunc
- type ForbiddenPaths
- type GenericResponse
- type HMAC
- type HTTPWork
- type HandlerMap
- type HealthCheckError
- type HealthCheckResult
- type HealthCheckStatus
- type HealthCheckWork
- type JSONAccessLog
- type Member
- type NoopResponseWriter
- type PageCache
- type Path
- type PathHandler
- type PathOptions
- func (p *PathOptions) Get(key string) interface{}
- func (p *PathOptions) GetBool(key string) bool
- func (p *PathOptions) GetDuration(key string) (time.Duration, error)
- func (p *PathOptions) GetInt64(key string) (int64, error)
- func (p *PathOptions) GetString(key string) string
- func (p *PathOptions) GetStringSlice(key string) []string
- type PathReplacer
- type PathStripper
- type Pool
- type PoolConfig
- type PoolID
- type PoolManager
- type PoolMaterializer
- type PoolOptions
- func (p *PoolOptions) Get(key string) interface{}
- func (p *PoolOptions) GetBool(key string) bool
- func (p *PoolOptions) GetFloat64(key string) float64
- func (p *PoolOptions) GetInt(key string) int
- func (p *PoolOptions) GetString(key string) string
- func (p *PoolOptions) GetStringSlice(key string) []string
- type Pools
- type ProcessInfo
- type ProxyResponseModifier
- type ProxyResponseModifierChain
- type PruneFunc
- type RateLimiter
- type Redirect
- type S3Pool
- type StatusFinisher
- type SuiteMap
- type TemplateError
- type Timeout
- type ZulipWork
Constants ¶
const ( // ErrBootstrapDone should not be treated as a proper error, as it is returned if Bootstrap // is complete (e.g. checkconfig or doc output), and won't continue for non-error reasons ErrBootstrapDone = Error("Bootstrap() is done. This is not necessarily an error") // ErrPoolBuild is a panic in bootstrap() if BuildPools fails ErrPoolBuild = Error("error building pools") // ErrValidateExtras is a panic in bootstrap() if there are any errors in ValidateExtras. // Preceding error output may provide more specific information. ErrValidateExtras = Error("error validating extras") // ErrVersion is a panic in bootstrap() if versionrequired is set in the config, but is less // than the VERSION constant of the compiled binary reading the config. ErrVersion = Error("version requirement not met") )
const ( // ErrSourceVerificationFailed is an error returned when an authentication source cannot be verified ErrSourceVerificationFailed = Error("cannot verify the provided source") // ErrSourceNotSupported is an error returned when the authentication source scheme is not supported [yet] ErrSourceNotSupported = Error("specified source scheme is not supported") )
const ( // ConfigGroupCachePeers is a config for a list of peers, ala “http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082“ ConfigGroupCachePeers = ConfigKey("groupcache.peerlist") // ConfigGroupCacheAddr is a config key for my listening address, ala “:8080“ ConfigGroupCacheAddr = ConfigKey("groupcache.listenaddress") // ConfigCacheSizeMB is the size- in megabytes- the cache should be. Defaults to 16. ConfigCacheSizeMB = ConfigKey("cache.sizemb") // ConfigCacheMaxItemSizeB is the size - in bytes - at which an item will not be cached. ConfigCacheMaxItemSizeB = ConfigKey("cache.maxitemsize") // ConfigCacheExpiration is the duration in which an item should live in the cache. Default is "until evicted". ConfigCacheExpiration = ConfigKey("cache.expiration") // ConfigCacheControlHeader is the value to append to a `Cache-Control` response header. Default is to omit the header. ConfigCacheControlHeader = ConfigKey("cache.controlheader") // NoCacheDefinedError is returned when a Path has CacheName set, but no cache has been globally configured. NoCacheDefinedError = Error("path requests a cache, but no cache defined") // CacheAlreadyDefinedError is returned when a Path has CacheName set, but that CacheName has already been used. CacheAlreadyDefinedError = Error("path requests a new cache that already exists") )
const ( ConfigAccessLog = ConfigKey("accesslog") ConfigAuthPool = ConfigKey("authpool") ConfigCheckConfig = ConfigKey("checkconfig") ConfigCommonLog = ConfigKey("commonlog") ConfigDebug = ConfigKey("debug") ConfigDebugLog = ConfigKey("debuglog") ConfigDebugRequests = ConfigKey("debugrequests") ConfigDebugResponses = ConfigKey("debugresponses") ConfigDebugTimings = ConfigKey("debugtimings") ConfigDumpConfig = ConfigKey("dumpconfig") ConfigEC2 = ConfigKey("ec2") ConfigErrorLog = ConfigKey("errorlog") ConfigHandlers = ConfigKey("handlers") ConfigHotConfig = ConfigKey("hotconfig") ConfigHotUpdate = ConfigKey("hotupdate") ConfigKeepaliveTimeout = ConfigKey("keepalivetimeout") ConfigKeys = ConfigKey("keys") ConfigKeysAwsRegion = ConfigKey("keys.aws.region") ConfigKeysAwsAccessKey = ConfigKey("keys.aws.access") ConfigKeysAwsSecretKey = ConfigKey("keys.aws.secret") ConfigListen = ConfigKey("listen") ConfigLogAge = ConfigKey("logage") ConfigLogBackups = ConfigKey("logbackups") ConfigLogSize = ConfigKey("logsize") ConfigMaxConnections = ConfigKey("maxconnections") ConfigPaths = ConfigKey("paths") ConfigPools = ConfigKey("pools") ConfigRequestIDHeaderName = ConfigKey("requestidheadername") ConfigSlowLog = ConfigKey("slowlog") ConfigSlowRequestMax = ConfigKey("slowrequestmax") ConfigStripRequestHeaders = ConfigKey("striprequestheaders") ConfigTempFolder = ConfigKey("tempfolder") ConfigTimeout = ConfigKey("timeout") ConfigTrustRequestIDHeader = ConfigKey("trustrequestidheader") ConfigUpdatePath = ConfigKey("updatepath") ConfigAuthoritativeDomains = ConfigKey("authoritativedomains") ConfigVersionRequired = ConfigKey("versionrequired") ConfigLogFakeXFF = ConfigKey("fakexfflog") ConfigURLRouteHeaders = ConfigKey("urlroute.enableheaders") ConfigURLRouteIDHeaderName = ConfigKey("urlroute.idheadername") ConfigURLRouteEndpointHeaderName = ConfigKey("urlroute.endpointheadername") ConfigURLRouteNameHeaderName = ConfigKey("urlroute.nameheadername") ConfigPoolHeaderName = ConfigKey("urlroute.poolheadername") ConfigPoolMemberHeaderName = ConfigKey("urlroute.poolmemberheadername") )
Constants for configuration key strings
const ( ConfigCORSAllowCredentials = ConfigKey("CORS.allowcredentials") ConfigCORSAllowHeaders = ConfigKey("CORS.allowheaders") ConfigCORSAllowMethods = ConfigKey("CORS.allowmethods") ConfigCORSOrigins = ConfigKey("CORS.origins") ConfigCORSMaxAge = ConfigKey("CORS.maxage") ConfigCORSPrivateNetwork = ConfigKey("CORS.privatenetwork") CORSAllowOrigin = CorsString("Access-Control-Allow-Origin") CORSAllowCredentials = CorsString("Access-Control-Allow-Credentials") CORSExposeHeaders = CorsString("Access-Control-Expose-Headers") CORSAllowMethods = CorsString("Access-Control-Allow-Methods") CORSAllowHeaders = CorsString("Access-Control-Allow-Headers") CORSMaxAge = CorsString("Access-Control-Max-Age") CORSPrivateNetwork = CorsString("Access-Control-Request-Private-Network") )
Constants for configuration key strings
const ( // ErrCiphertextTooShort is returned when the ciphertext is too damn short ErrCiphertextTooShort = Error("ciphertext too short") // ErrCiphertextIrregular is returned when the ciphertext is not a multiple of the block size ErrCiphertextIrregular = Error("ciphertext is not a multiple of the block size") )
const ( ConfigTLSCerts = ConfigKey("tls.certs") ConfigTLSCiphers = ConfigKey("tls.ciphers") ConfigTLSEnabled = ConfigKey("tls.enabled") ConfigTLSHTTPRedirects = ConfigKey("tls.httpredirects") ConfigTLSKeepaliveDisabled = ConfigKey("tls.keepalivedisabled") ConfigTLSListen = ConfigKey("tls.listen") ConfigTLSMaxVersion = ConfigKey("tls.maxversion") ConfigTLSMinVersion = ConfigKey("tls.minversion") ConfigTLSHTTP2 = ConfigKey("tls.http2") )
Constants for configuration key strings
const ( // ErrPreviousError is exclusive to the HandleSuddenEviction scheme, // and announces that original error should be the one returned to the caller ErrPreviousError = Error("previous error stands") // ErrAuthError is used to communicate authentication errors. More detail // will be in the error log, but let's not leak that, shall we? ErrAuthError = Error("an error occurred during AAA") // ErrForbiddenError is used to communicate resource access denial ErrForbiddenError = Error("you do not have access to this resource") // ErrNoSession is called when an AWS feature is called, but there is no initialized AWS session ErrNoSession = Error("there is no initialized AWS session") // ErrUnknownError is returned when an error occurs for undefined-yet-anticipated reasons ErrUnknownError = Error("unknown error") )
const ( ConfigErrorHandlerTemplate = ConfigKey("errorhandler.template") ConfigErrorHandlerURI = ConfigKey("errorhandler.uri") )
Constants for configuration key strings
const ( StatusClientClosedRequest = 499 StatusClientClosedRequestText = "Client Closed Request" )
Constants for miscellaneous conditions
const ( // PathOptionsKey is a keyid for setting/getting PathOptions to/from a Context PathOptionsKey commonIDKey // ErrAborted is only used during panic recovery, if http.ErrAbortHandler was called ErrAborted = Error("client aborted connection, or connection closed") )
const ( ConfigHeaders = ConfigKey("headers") ConfigRecovererLogStackTraces = ConfigKey("Recoverer.logstacktraces") )
Constants for configuration key strings
const ( // ErrNoSuchEntryError is returned by the Status Registry when no status exists for the requested thing ErrNoSuchEntryError = Error("no such element exists") // ErrNoSuchHealthCheckStatus is returned when a string-based status has been used, but no corresponding HealthCheckStatus exists ErrNoSuchHealthCheckStatus = Error("no such HealthCheckStatus exists") )
const ( ConfigHMACKey = ConfigKey("hmac.key") ConfigHMACSalt = ConfigKey("hmac.salt") ConfigHMACExpiration = ConfigKey("hmac.expiration") ConfigHMACExpirationName = ConfigKey("hmac.expirationfield") )
PathOptions for HMAC signing
const ( ConfigCompression = ConfigKey("compression") ConfigDisableRealAddr = ConfigKey("disablerealaddr") ConfigForbiddenPaths = ConfigKey("forbiddenpaths") )
Constants for configuration key strings
const ( // ErrPoolsConfigdefaultmembererrorstatusInvalid is returned when the pools.defaultmembererrorstatus is set improperly ErrPoolsConfigdefaultmembererrorstatusInvalid = Error("pools.defaultmembererrorstatus is set to an invalid HealthCheckStatus") // ErrPoolsConfigdefaultmembererrorstatusEmpty is returned when the pools.defaultmembererrorstatus is empty ErrPoolsConfigdefaultmembererrorstatusEmpty = Error("pools.defaultmembererrorstatus is empty") // ErrPoolStickyAESNoKey is returned when materializing a Pool with StickyCookieType set to 'aes' but 'keys.stickycookie' is not set ErrPoolStickyAESNoKey = Error("Pool.StickyCookieType set to 'aes' but no keys.stickycookie set") // ErrPoolAddMemberNotSupported is returned when Pool.AddMember is called on a Pool that doesn't support the operation ErrPoolAddMemberNotSupported = Error("this Pool does not support dynamic adding of members") // ErrPoolDeleteMemberNotSupported is returned when Pool.DeleteMember is called on a Pool that doesn't support the operation ErrPoolDeleteMemberNotSupported = Error("this Pool does not support dynamic deletion of members") // ErrPoolRemoveMemberNotSupported is returned when Pool.RemoveMember is called on a Pool that doesn't support the operation ErrPoolRemoveMemberNotSupported = Error("this Pool does not support dynamic removing of members") // ErrPoolNoMembersConfigured is returned when a non-dynamic Pool type (e.g. S3) has no members configured ErrPoolNoMembersConfigured = Error("no members configured for a non-dynamic Pool") // ErrPoolConfigConsistentAndSticky is returned when a Pool has both Sticky and ConsistentHashing set ErrPoolConfigConsistentAndSticky = Error("a Pool cannot have Sticky and ConsistentHashing set") // ErrPoolConfigMissing is returned when an operation on a Pool is requested, but no config is set ErrPoolConfigMissing = Error("no Config present for Pool") )
const ( ConfigKeysStickyCookie = ConfigKey("keys.stickycookie") ConfigStickyCookieAESTTL = ConfigKey("stickycookie.aes.ttl") ConfigStickyCookieHTTPOnly = ConfigKey("stickycookie.httponly") ConfigStickyCookieSecure = ConfigKey("stickycookie.secure") ConfigConsistentHashPartitions = ConfigKey("consistenthash.partitions") ConfigConsistentHashReplications = ConfigKey("consistenthash.replfactor") ConfigConsistentHashLoad = ConfigKey("consistenthash.load") )
Constants for configuration key strings
const ( // ErrConsistentHashNextServerUnsupported is returned if NextServer is called ErrConsistentHashNextServerUnsupported = Error("Consistent Hash Pools don't support NextServer") // ErrConsistentHashInvalidSource is returned the source is not one of "request", "header", or "cookie" ErrConsistentHashInvalidSource = Error("the consistent hash source provided is not valid") // ErrConsistentHashSourceNameImbalance is returned when the configured lists are not of the same lengths ErrConsistentHashSourceNameImbalance = Error("ConsistentHashSources and ConsistentHashNames are not balanced lists") )
const ( // ErrNoSuchMemberError is returned if the member doesn't exist or has been removed from a Pool ErrNoSuchMemberError = Error("member no longer exists in pool") // NoPoolsError is returned if there are no pools, but a Build was requested NoPoolsError = Error("there are no pools to build") )
const ( ConfigPoolsDefaultMemberErrorStatus = ConfigKey("pools.defaultmembererrorstatus") ConfigPoolsDefaultMemberWeight = ConfigKey("pools.defaultmemberweight") ConfigPoolsHealthcheckInterval = ConfigKey("pools.healthcheckinterval") ConfigPoolsLocalMemberWeight = ConfigKey("pools.localmemberweight") ConfigPoolsPreMaterialize = ConfigKey("pools.prematerialize") ConfigPoolsDefaultConsistentHashPartitions = ConfigKey("pools.defaultconsistenthashpartitions") ConfigPoolsDefaultConsistentHashReplicationFactor = ConfigKey("pools.defaultconsistenthashreplicationfactor") ConfigPoolsDefaultConsistentHashLoad = ConfigKey("pools.defaultconsistenthashload") )
Constants for configuration key strings
const ( ConfigS3StreamProxyName = ConfigKey("s3proxy.name") ConfigS3StreamProxyBucket = ConfigKey("s3proxy.bucket") ConfigS3StreamProxyPrefix = ConfigKey("s3proxy.prefix") ConfigS3StreamProxyRedirectURL = ConfigKey("s3proxy.redirecturl") ConfigS3StreamProxyFormNameField = ConfigKey("s3proxy.namefield") ConfigS3StreamProxyFormEmailField = ConfigKey("s3proxy.emailfield") ConfigS3StreamProxyFormToField = ConfigKey("s3proxy.tofield") ConfigS3StreamProxyFormFileField = ConfigKey("s3proxy.filefield") ConfigS3StreamProxyBadFileExtensions = ConfigKey("s3proxy.badfileexts") ConfigS3StreamProxyWrapSuccess = ConfigKey("s3proxy.wrapsuccess") ConfigS3StreamProxyZulipStream = ConfigKey("s3proxy.zulipstream") ConfigS3StreamProxyZulipTopic = ConfigKey("s3proxy.zuliptopic") )
Constants for configuration key strings
const ( ConfigTUSTargetURI = ConfigKey("tus.targeturi") ConfigTUSAppendFilename = ConfigKey("tus.appendfilename") ErrTUSTargetURIMissing = Error("tus.targeturi missing from path options") )
Constants for configuration key strings and Errors
const ( // ErrUpdateConfigS3NoAWS is returned when the s3 updatepath is set, but AWS is not. ErrUpdateConfigS3NoAWS = Error("s3 updatepath set, but AWS is not configured") // ErrUpdateConfigEmptyURL is returned when the updatepath is empty ErrUpdateConfigEmptyURL = Error("update url is empty, not updating") )
const ( ConfigMapFiles = ConfigKey("mapfiles") ConfigMapIDMap = ConfigKey("urlroute.idmap") ConfigMapEndpointMap = ConfigKey("urlroute.endpointmap") ConfigSwitchHandlerEnforce = ConfigKey("SwitchHandler.enforce") ConfigSwitchHandlerStripPrefix = ConfigKey("SwitchHandler.stripprefix") // e.g. xzy strips ^xyz.*- )
Constants for configuration key strings
const ( ConfigZulipBaseURL = ConfigKey("zulip.url") ConfigZulipUsername = ConfigKey("zulip.username") ConfigZulipToken = ConfigKey("zulip.token") ConfigZulipRetryCount = ConfigKey("zulip.retrycount") ConfigZulipRetryInterval = ConfigKey("zulip.retryinterval") )
Constants for configuration key strings
const ( ConfigWorkersInitialPoolSize = ConfigKey("workers.initialpoolsize") ConfigWorkersMaxPoolSize = ConfigKey("workers.maxpoolsize") ConfigWorkersMinPoolSize = ConfigKey("workers.minpoolsize") ConfigWorkersQueueSize = ConfigKey("workers.queuesize") ConfigWorkersResizeInterval = ConfigKey("workers.resizeinterval") )
Constants for configuration key strings
const (
ConfigMacros = ConfigKey("macros")
)
Constants for configuration key strings
const ( // ErrFinisher404 returned by HandleFinisher if the requested finisher doesn't exist. Other errors should be treated as failures ErrFinisher404 = Error("requested finisher does not exist") )
const ( // ErrInvalidS3URL is returned when the relevant URL parts from the provided S3 URL cannot be derived ErrInvalidS3URL = Error("the S3 URL passed is invalid") )
const ( // ErrNoZulipClient is returned by a worker when there is no Zulip client defined ErrNoZulipClient = Error("no Zulip client defined") )
const ( // ErrS3ProxyConfigNoAWS is returned when the s3proxy is used, but AWS is not. ErrS3ProxyConfigNoAWS = Error("s3proxy used, but AWS is not configured") )
Variables ¶
var ( // Conf is the config struct Conf *viper.Viper // StopFuncs is an aggregator for functions that needs to be called during graceful shutdowns. // Can only be called once! StopFuncs = funcregistry.NewFuncRegistry(true) // StrainFuncs is an aggregator for functions that can be called when JAR is under resource pressure. StrainFuncs = funcregistry.NewFuncRegistry(false) // InitFuncs are called in the early phases of Bootstrap() InitFuncs = funcregistry.NewFuncRegistry(true) // FileWatcher is an abstracted mechanism for calling WatchHandlerFuncs when a file is changed FileWatcher *watcher.Watcher // LoadBalancers are Pools LoadBalancers *Pools // Seq is a Sequence used for request ids Seq = sequence.New(1) // AWSSession is an aws.Session for use in various places AWSSession *aws.Session // Caches is a GroupCache used for various subsystems Caches *CacheCluster // Hostname is a local cache of os.Hostname Hostname string )
var ( // ConfigValidations is used to wire in func()error to be run, validating distributed configs ConfigValidations = make(map[string]func() error) // ConfigAdditions is used to wire in additional default configurations ConfigAdditions = make(configDefaultSetter) )
var ( // Finishers is a map of available HandlerFuncs Finishers = make(FinisherMap) // FinisherSetups is a map of Finishers that need exec-time setup checks FinisherSetups = make(map[string]FinisherSetupFunc) )
var ( // Metrics is a Registry for metrics, to be reported in the healthcheck Metrics = metrics.NewRegistry() // Status is a Registry for statuses, to be reported in the healthcheck Status = health.NewStatusRegistry() // NUMCPU is the number of CPUs at starttime NUMCPU = runtime.NumCPU() // GOVERSION is the version of Go GOVERSION = runtime.Version() // Counter is the clicker to a request counter. Counter func() // ThisProcess is updated information about this process ThisProcess *ProcessInfo // ConnectionCounter is used for tracking the current number of connections served ConnectionCounter int64 // CurrentHealthCheck is a cache of the current state, refreshed periodically CurrentHealthCheck atomic.Value // HealthCheck is a Finisher that writes the healthcheck HealthCheck = healthCheckAsync // TerseHealthCheck is a Finisher that writes the terse healthcheck TerseHealthCheck = terseHealthCheckAsync )
var ( // CheckAuthoritative compares domain suffixes in the "authoritativedomains" against the requested URL.Hostname() // and returns true if it matches or if "authoritativedomains" is not used CheckAuthoritative = func(*http.Request) bool { return true } // RecyclableBufferPool is a pool of recyclable.Buffers that are safe to Get() and use (after a reset), and then // Close() them when you're done, to put them back in the Pool RecyclableBufferPool = recyclable.NewBufferPool() )
var ( // OutFormat is a log.Logger format used by default OutFormat = log.Ldate | log.Ltime | log.Lshortfile // DebugOut is a log.Logger for debug messages DebugOut = log.New(io.Discard, "[DEBUG] ", 0) // TimingOut is a log.Logger for timing-related debug messages. DEPRECATED TimingOut = log.New(io.Discard, "[TIMING] ", 0) // ErrorOut is a log.Logger for error messages ErrorOut = log.New(os.Stderr, "", OutFormat) // AccessOut is a log.Logger for access logging. PLEASE DO NOT USE THIS DIRECTLY AccessOut = log.New(os.Stdout, "", 0) // CommonOut is a log.Logger for Apache "common log format" logging. PLEASE DO NOT USE THIS DIRECTLY CommonOut = log.New(io.Discard, "", 0) // SlowOut is a log.Logger for slow request information SlowOut = log.New(io.Discard, "", 0) // RequestTimer is a function to allow Durations to be added to the Timer Metric RequestTimer func(time.Duration) // SlowRequests is the slow request log Duration SlowRequests time.Duration // LogPool is a Pool of AccessLogs LogPool sync.Pool )
var ( // DefaultTrip should be used instead of the http.DefaultTransport, for pools/etc. DefaultTrip http.RoundTripper // DefaultClient should be used instead of using http.DefaultClient, for pools/etc. DefaultClient *http.Client // DefaultMemberWeight is the weight added to each member by default DefaultMemberWeight int // LocalMemberWeight is the weight assigned to each member that is AZ-local LocalMemberWeight int // ResponseModifierChain is a ProxyResponseModifierChain to handle sequences of modifications // use “ResponseModifierChain.Add()“ to add your own ResponseModifierChain ProxyResponseModifierChain // Materializers is a map of available PoolMaterializers Materializers = make(map[string]PoolMaterializer) )
var ( // RestartSelf is a niladic that will trigger a graceful restart of this process RestartSelf func() // IntSelf is a niladic that will trigger an interrupt of this process IntSelf func() // KillSelf is a niladic that will trigger a graceful shutdown of this process KillSelf func() )
var ( // Workers are a pool of workers Workers *workers.WorkerPool // AddWork queues up some work for workers AddWork func(workers.Work) )
var ( // CorsHandler is the global handler for CORS CorsHandler func(next http.Handler) http.Handler )
var ( // ErrorTemplate is an HTML template for returning errors ErrorTemplate *template.Template )
var ( // Handlers is a map of available Handlers (middlewares) Handlers = make(HandlerMap) )
var ( // MacroDictionary is a Dictionary for doing mcro MacroDictionary dictionary.Resolver )
var ( // SwitchMaps are maps of URLs parts and their IDs and/or endpoints SwitchMaps = mapmap.NewMapMap() )
var (
// TaskRegistry is for wrangling scheduled tasks
TaskRegistry cronzilla.Wrangler
)
var ( // VERSION is the internal code revision number VERSION string = "1.1.0+git" )
var ZulipClient *zulip.Zulip
ZulipClient is a global Zulip client to use for messaging, or nil if not
Functions ¶
func AccessLogHandler ¶
AccessLogHandler is a middleware that times how long requests takes, assembled an AccessLog, and logs accordingly
func AddMetrics ¶
AddMetrics ranges over the supplied map, adding each as a Metric to the supplied Check
func AddStatuses ¶
func AddStatuses(s *health.StatusRegistry, hc *health.Check) *health.Check
AddStatuses ranges over the supplied StatusRegistry, adding each as a Service to the supplied Check
func AuthoritativeDomainsHandler ¶
AuthoritativeDomainsHandler declines to handle requests that are not listed in "authoritativedomains" config
func Bootstrap ¶
func Bootstrap()
Bootstrap assumes that the Conf object is all set, for now at least, builds the necessary subsystems and starts running.
Bootstrap doesn't return unless the server exits
func BootstrapChan ¶
func BootstrapChan(closer chan struct{})
BootstrapChan assumes that the Conf object is all set, for now at least, builds the necessary subsystems and starts running.
BootstrapChan doesn't return unless the server exits or the passed chan is closed
func BuildPath ¶
BuildPath does the heavy lifting to build a single path (which may result in multiple paths, but that's just bookkeeping)
func BuildPaths ¶
BuildPaths unmarshalls the paths config, creates handler chains, and updates the mux
func ChanBootstrap ¶
func ChanBootstrap() chan error
ChanBootstrap assumes that the Conf object is all set, for now at least, builds the necessary subsystems and starts running.
ChanBootstrap returns quickly, and should be assumed running unless an error is received on the returned chan. ErrBootstrapDone should not be treated as a proper error, as it is returned if Bootstrap is complete (e.g. checkconfig or doc output)
func ConnectionCounterAdd ¶
func ConnectionCounterAdd()
ConnectionCounterAdd atomically adds 1 to the ConnectionCounter
func ConnectionCounterGet ¶
func ConnectionCounterGet() int64
ConnectionCounterGet atomically returns the current value of the ConnectionCounter
func ConnectionCounterRemove ¶
func ConnectionCounterRemove()
ConnectionCounterRemove atomically adds -1 to the ConnectionCounter
func CopyHeaders ¶
CopyHeaders copies http headers from source to destination, it does not overide, but adds multiple headers
func CopyRequest ¶
CopyRequest provides a safe copy of a bodyless request into a new request
func DateFinisher ¶ added in v1.3.0
func DateFinisher(w http.ResponseWriter, r *http.Request)
DateFinisher is a Finisher that simply returns the current system datestamp as a string, for cache testing.
func DumpFinisher ¶
func DumpFinisher(w http.ResponseWriter, r *http.Request)
DumpFinisher is a special finisher that reflects a ton of request output
func DumpHandler ¶
DumpHandler is a special handler that ships a ton of request output to DebugLog
func ECBDecrypt ¶
ECBDecrypt takes a base64-encoded key and RawURLencoded-base64 ciphertext to decrypt, and returns the plaintext or an error. PKCS5 padding is trimmed as needed
func ECBEncrypt ¶
ECBEncrypt takes a base64-encoded key and a []byte, and returns the base64-encdoded ciphertext or an error. PKCS5 padding is added as needed
func EndpointDecider ¶
func EndpointDecider(w http.ResponseWriter, r *http.Request)
EndpointDecider is a Finisher that inspects the “switchEndpointKey“ context to determine which materialized Pool should get the request. Requests for clusters that are not materialized, or not having the “clustername“ context value set will result in unrecoverable errors
func FileExists ¶
FileExists returns true if the provided path exists, and is not a directory
func FlashEncoding ¶
FlashEncoding returns a URL-encoded version of the provided string, with "+" additionally converted to "%2B"
func FolderExists ¶
FolderExists returns true if the provided path exists, and is a directory
func Forbidden ¶
func Forbidden(w http.ResponseWriter, r *http.Request)
Forbidden is a Finisher that returns 403 for the requested Path
func GetErrorLog ¶
GetErrorLog gets an error-type log
func GetLogOrDiscard ¶
GetLogOrDiscard gets a standard-type log, or discards the output
func GetRequestID ¶
GetRequestID is returns a requestID from a context, or the empty string
func GetSwitchName ¶
GetSwitchName is a function to return the switch name in a request's context, if present
func HandleFinisher ¶
func HandleFinisher(handler string, path *Path) (http.HandlerFunc, error)
HandleFinisher takes a Finisher HandlerFunc name, and returns the function for it and nil, or nil and and error
func HandleGenericWrapper ¶
func HandleGenericWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
HandleGenericWrapper is essentially a noop for when no tempate or remote errorhandler is defined
func HandleHandler ¶
HandleHandler takes a handler name, and an existing chain, and returns a new chain or an error
func HandleReload ¶
HandleReload waits 5 seconds after being called, and then rebuilds the SwitchMaps
func HandleRemoteWrapper ¶
func HandleRemoteWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
HandleRemoteWrapper wraps errors (HTTP codes >= 400) in a pretty wrapper for client presentation, using a Worker to make a subrequest to an error-wrapping API
func HandleTemplateWrapper ¶
func HandleTemplateWrapper(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool
HandleTemplateWrapper wraps errors (HTTP codes >= 400) in a pretty wrapper for client presentation, using a template
func InitConfig ¶
InitConfig creates an config, initialized with defaults and environment-set values, and returns it
func LoadConfig ¶
LoadConfig read the config file and returns a config object or an error
func MinuteDelayer ¶
func MinuteDelayer(w http.ResponseWriter, r *http.Request)
MinuteDelayer is a special finisher that waits for 60s before returning
func MinuteStreamer ¶
func MinuteStreamer(w http.ResponseWriter, r *http.Request)
MinuteStreamer is a special finisher that writes the next number, once a secondish, for 60 iterations
func NewECBDecrypter ¶
NewECBDecrypter should never be used unless you know what you're doing
func NewECBEncrypter ¶
NewECBEncrypter should never be used unless you know what you're doing
func NewStickyPool ¶ added in v1.2.0
func NewStickyPool(poolName, cookieName, cookieType string, next http.Handler, opts ...roundrobin.LBOption) (*roundrobin.RoundRobin, error)
NewStickyPool returns a primed RoundRobin that honors pinning based on a cookie value
func OkFinisher ¶
func OkFinisher(w http.ResponseWriter, r *http.Request)
OkFinisher is a Finisher that simply returns "Ok", for throughput testing.
func PoolLister ¶
func PoolLister(w http.ResponseWriter, r *http.Request)
PoolLister is a finisher to list the pools
func PoolMemberAdder ¶
func PoolMemberAdder(w http.ResponseWriter, r *http.Request)
PoolMemberAdder is a finisher to add a member to an existing pool
func PoolMemberLister ¶
func PoolMemberLister(w http.ResponseWriter, r *http.Request)
PoolMemberLister is a finisher to list the members of an existing pool
func PoolMemberLoser ¶
func PoolMemberLoser(w http.ResponseWriter, r *http.Request)
PoolMemberLoser is a finisher to remove a member from an existing pool
func PrettyPrint ¶
func PrettyPrint(v interface{}) string
PrettyPrint returns the a JSONified version of the string, or %+v if that's not possible
func ReaderToString ¶
ReaderToString reads from a Reader into a Buffer, and then returns the string value of that
func ReplaceURI ¶
ReplaceURI standardizes the replacement of the Request.URL.Path and Request.RequestURI, which are squirrely at best.
func RequestErrorResponse ¶
RequestErrorResponse is the functional equivalent of ErrRequestError .WrappedResponse(..)
func RequestErrorString ¶
RequestErrorString is the functional equivalent of ErrRequestError .String()
func RequestIDFinisher ¶ added in v1.3.0
func RequestIDFinisher(w http.ResponseWriter, r *http.Request)
RequestIDFinisher is a Finisher that simply returns the current requestID a random number of times, for grind testing.
func ResponseHeaders ¶
ResponseHeaders is a simple piece of middleware that sets configured headers
func Restart ¶
func Restart(w http.ResponseWriter, r *http.Request)
Restart signals the server to restart itself
func RouteIDInspectionHandler ¶
RouteIDInspectionHandler checks the Query params for a ROUTEID and shoves it into a cookie
func S3StreamProxyFinisher ¶
func S3StreamProxyFinisher(w http.ResponseWriter, r *http.Request)
S3StreamProxyFinisher is a finisher that streams a POSTd file to an S3 bucket
func SetupHandler ¶
SetupHandler adds the RequestID and various other informatives to a request context
func Stack ¶
func Stack(w http.ResponseWriter, r *http.Request)
Stack is a Finisher that dumps the current stack to the request
func StringIfCtx ¶
StringIfCtx will return a non-empty string if the suppled Request has a Context.WithValue() of the specified name
func StringToCleanList ¶ added in v1.3.0
StringToCleanList splits 'in' using 'sep'arator, trims any leading/trailing space from each resulting string, and returns the list
func SwitchHandler ¶
SwitchHandler adds URL switching information to the request context
func TestFinisher ¶
func TestFinisher(w http.ResponseWriter, r *http.Request)
TestFinisher is a special finisher that outputs some detectables
func TrimPrefixURI ¶
TrimPrefixURI standardizes the prefix trimming of the Request.URL.Path and Request.RequestURI, which are squirrely at best.
func URLCaptureHandler ¶
URLCaptureHandler is an unchainable handler that captures the Hostname of the Pool Member servicing a request
func Unzip ¶
Unzip takes a source zip, and a destination folder, and unzips source into dest, returning an error if appropriate
func Update ¶
func Update(w http.ResponseWriter, r *http.Request)
Update signals the updater to update itself
func ValidateExtras ¶
func ValidateExtras() []error
ValidateExtras runs through a list of referenced functions, and returns any errors they return. All functions will be run, so an array of errors may be returned
Types ¶
type Access ¶
type Access struct {
// contains filtered or unexported fields
}
Access is a type to provide binary validation of addresses, based on the contents of "Allow/Deny" rules.
func NewAccessFromStrings ¶
NewAccessFromStrings is the safest way to create a safe, valid Access type. The supplied "allow" and "deny" strings may be comma-delimited lists of IP addresses and/or CIDR networks.
func (*Access) AccessHandler ¶
AccessHandler is a handler that consults r.RemoteAddr and validates it against the Access type.
func (*Access) AddAddress ¶
AddAddress adds the supplied address to either the allow or deny lists, depending on the value of the suppled boolean. An error is returned if the supplied address cannot be parsed.
type AccessLog ¶
type AccessLog interface { // CommonLogFormat will return the contents as a CLF-compatible string. If combined is set, a "combined" CLF is included (adds referer and user-agent) CommonLogFormat(combined bool) string // Reset will empty out the contents of the access log Reset() // ResponseFiller adds response information to the AccessLog entry ResponseFiller(responseTime time.Time, responseDuration time.Duration, responseCode int, responseLength int) // RequestFiller adds request information to the AccessLog entry RequestFiller(r *http.Request) }
AccessLog is an interface providing base logging, but allowing addons to extent it easily
type BasicAuth ¶
type BasicAuth struct { // List of allowed users Users []string // contains filtered or unexported fields }
BasicAuth wraps a handler requiring HTTP basic auth
func NewBasicAuth ¶
NewBasicAuth takes a source, realm, and list of users, returning an initialized *BasicAuth
func NewVerifiedBasicAuth ¶
NewVerifiedBasicAuth takes a source, realm, and list of users, verifies the auth source, and returns an initialized *BasicAuth or an error
func (*BasicAuth) Authenticate ¶
Authenticate takes a username, password, realm, and return bool if the authentication is positive
func (*BasicAuth) VerifySource ¶
VerifySource checks that the requested authentication source is valid, and accessible
type BodyByteLimit ¶
type BodyByteLimit struct {
// contains filtered or unexported fields
}
BodyByteLimit is a Request.Body size limiter
func NewBodyByteLimit ¶
func NewBodyByteLimit(limit int64) BodyByteLimit
NewBodyByteLimit returns an initialized BodyByteLimit
type CORS ¶
type CORS struct { AllowCredentials string AllowMethods string AllowHeaders string MaxAge string PrivateNetwork string // contains filtered or unexported fields }
CORS is an abstraction to handle CORS header nonsense. In order to keep origin comparisons as fast as possible, the expressions are pre-compiled, and thus need to either be added via AddOrigins() or supplied to NewCORSFromConfig().
func NewCORSFromConfig ¶
NewCORSFromConfig returns an initialized CORS struct from a list of origins and a config map
func (*CORS) Handler ¶
Handler is a middleware that validates Origin request headers against a whitelist of expressions, and may change the response headers accordingly
func (*CORS) ResponseModifier ¶
ResponseModifier is an oxy/forward opsetter to remove CORS headers from responses
type CacheCluster ¶ added in v1.3.0
type CacheCluster struct { *cache.GroupCache // contains filtered or unexported fields }
CacheCluster is our internal representation of GroupCache
func NewCacheCluster ¶ added in v1.3.0
func NewCacheCluster(address string, peers []string) *CacheCluster
NewCacheCluster should be called at most once, and returns an initialized CacheCluster
func (*CacheCluster) NewPageCache ¶ added in v1.3.0
func (cc *CacheCluster) NewPageCache(name string, cacheSize, maxItemSize int64, itemExpiration time.Duration, cacheControlHeader string) (*PageCache, error)
NewPageCache should be called at most once per unique "name", and returns an initialized PageCache
type Compression ¶
type Compression struct {
// contains filtered or unexported fields
}
Compression is used to support GZIP compression of data en route to a client
func NewCompression ¶
func NewCompression(contentTypes []string) *Compression
NewCompression returns a pointer to a Compression struct with the specified MIME-types baked in
type ConfigKey ¶
type ConfigKey = string
ConfigKey is a string type for static config key name consistency
type ConsistentHashPool ¶ added in v1.2.0
type ConsistentHashPool struct {
// contains filtered or unexported fields
}
ConsistentHashPool is a PoolManager that implements a consistent hash on a key to return the proper member consistently
func NewConsistentHashPool ¶ added in v1.2.0
func NewConsistentHashPool(source, key string, pool *Pool, next http.Handler) (*ConsistentHashPool, error)
NewConsistentHashPool returns a primed ConsistentHashPool
func NewConsistentHashPoolOpts ¶ added in v1.2.0
func NewConsistentHashPoolOpts(sourceKeys []hashSource, partitionCount, replicationFactor int, load float64, pool *Pool, next http.Handler) (*ConsistentHashPool, error)
NewConsistentHashPoolOpts exposes some internal tunables, but still returns a ConsistentHashPool
func (*ConsistentHashPool) Next ¶ added in v1.2.0
func (ch *ConsistentHashPool) Next() http.Handler
Next returns the specified next Handler
func (*ConsistentHashPool) NextServer ¶ added in v1.2.0
func (ch *ConsistentHashPool) NextServer() (*url.URL, error)
NextServer is an error-causing noop to implement PoolManager
func (*ConsistentHashPool) RemoveServer ¶ added in v1.2.0
func (ch *ConsistentHashPool) RemoveServer(u *url.URL) error
RemoveServer removes the specified member from the pool
func (*ConsistentHashPool) ServeHTTP ¶ added in v1.2.0
func (ch *ConsistentHashPool) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles its part of the request
func (*ConsistentHashPool) ServerWeight ¶ added in v1.2.0
func (ch *ConsistentHashPool) ServerWeight(u *url.URL) (int, bool)
ServerWeight is a noop to implement PoolManager
func (*ConsistentHashPool) Servers ¶ added in v1.2.0
func (ch *ConsistentHashPool) Servers() []*url.URL
Servers returns a list of member URLs
func (*ConsistentHashPool) UpsertServer ¶ added in v1.2.0
func (ch *ConsistentHashPool) UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error
UpsertServer adds or updates the member to the pool
type CorsString ¶
type CorsString = string
CorsString is a string type for static string consistency
type DebugTrip ¶
type DebugTrip struct { // RTFunc is executed when RoundTrip() is called on a request. // It can be changed at any point to aid in changing conditions RTFunc func(*http.Request) (*http.Response, error) }
DebugTrip is an http.RoundTripper with a pluggable core func to aid in debugging
type ErrConfigurationError ¶
type ErrConfigurationError struct {
// contains filtered or unexported fields
}
ErrConfigurationError is returned when a debilitating configuration error occurs. If this is the initial configuration load, the program should exit. If this is a reload, the reload should abort and the known-working configuration should persist
func (ErrConfigurationError) Error ¶
func (e ErrConfigurationError) Error() string
type ErrRequestError ¶
ErrRequestError should be returned whenever an error is returned to a requestor. Care should be taken not to expose dynamic information inside the message. The request id will be automatically added to the message
func (ErrRequestError) Bytes ¶
func (e ErrRequestError) Bytes() []byte
Bytes returns a []byte of the error
func (ErrRequestError) Error ¶
func (e ErrRequestError) Error() string
Error returns a string of the error
func (ErrRequestError) String ¶
func (e ErrRequestError) String() string
String returns a string of the error
func (ErrRequestError) WrappedResponse ¶
func (e ErrRequestError) WrappedResponse(code int, w http.ResponseWriter)
WrappedResponse writes the templatized version of the error to a PRW
type ErrorWrapper ¶
type ErrorWrapper struct { // E takes the error code, request, a PluggableResponseWriter, and the original body, // and returns boolean true IFF rw has been written to. E should not change // headers as they may be ignored. E func(code int, r *http.Request, rw *prw.PluggableResponseWriter, body []byte) bool }
An ErrorWrapper is a struct to abstract error wrapping
type FinisherMap ¶
type FinisherMap map[string]http.HandlerFunc
FinisherMap maps Finisher names to their HandlerFuncs
func (*FinisherMap) List ¶
func (h *FinisherMap) List() []string
List returns the names of all of the Finishers
type FinisherSetupFunc ¶ added in v1.2.0
type FinisherSetupFunc func(*Path) (http.HandlerFunc, error)
FinisherSetupFunc is declared for Finishers that need exec-time setup checks
type ForbiddenPaths ¶
type ForbiddenPaths struct { // Paths is a list of compiled Regexps, because speed Paths []*regexp.Regexp }
ForbiddenPaths is a struct to assist in the expedient resolution of determining if a Request is destined to a forbidden path
func NewForbiddenPaths ¶
func NewForbiddenPaths(paths []string) (*ForbiddenPaths, error)
NewForbiddenPaths takes a list of regexp-compatible strings, and returns the analogous ForbiddenPaths with compiled regexps, or an error if a regexp could not be compiled
type GenericResponse ¶
GenericResponse is a Finisher that returns a possibly-wrapped response
func (*GenericResponse) Finisher ¶
func (gr *GenericResponse) Finisher(w http.ResponseWriter, r *http.Request)
Finisher is a ... Finisher for the instantiated GenericResponse
type HMAC ¶ added in v1.2.1
type HMAC struct { // If non-zero, the Handler will enforce timestamp (UnixMilli) comparison to "now" Expiration time.Duration // If set, this will be the name of the query parameter holding the timestamp. // If unset, "expiration" is assumed. ExpirationField string // contains filtered or unexported fields }
HMAC is a Handler that verifies the signature and possibly the timestamp of a request URL, and a Finisher that can sign URLs if so desired.
func NewHMAC ¶ added in v1.2.1
NewHMAC returns an initialized Verifier. If expiration is unset, expirations are not enforced.
type HTTPWork ¶
type HTTPWork struct { Client *http.Client Request *http.Request ResponseChan chan interface{} // RetryCount is the number of times to retry Request if there is an error RetryCount int //RetryInterval is the duration between retries RetryInterval time.Duration //RetryHTTPErrors, if set, classifies HTTP responses >= 500 as errors for retry purposes RetryHTTPErrors bool }
HTTPWork is a generic Work that can make HTTP requests
type HandlerMap ¶
HandlerMap maps handler names to their funcs
func (*HandlerMap) List ¶
func (h *HandlerMap) List() []string
List returns the names of all of the Handlers
type HealthCheckError ¶
type HealthCheckError struct { PoolName string URL string StatusCode int Prune bool ErrorStatus HealthCheckStatus Add PruneFunc Remove PruneFunc Err error }
HealthCheckError is an error returned through the HealthCheck system
func (*HealthCheckError) Error ¶
func (h *HealthCheckError) Error() string
Error returns the stringified version of the error
type HealthCheckResult ¶
type HealthCheckResult struct { PoolName string URL string StatusCode int Prune bool Add PruneFunc Remove PruneFunc }
HealthCheckResult is a non-error returned through the HealthCheck system
type HealthCheckStatus ¶
type HealthCheckStatus int
HealthCheckStatus is a specific int for HealthCheckStatus consts
const ( Unknown HealthCheckStatus = iota Ok Warning Critical )
Constants for HealthCheckStatuses
func StringToHealthCheckStatus ¶
func StringToHealthCheckStatus(hc string) (HealthCheckStatus, error)
StringToHealthCheckStatus takes a string HealthCheckStatus and returns the HealthCheckStatus or ErrNoSuchHealthCheckStatus
func (HealthCheckStatus) String ¶
func (i HealthCheckStatus) String() string
type HealthCheckWork ¶
type HealthCheckWork struct { PoolName string Member string URL string Prune bool ErrorStatus HealthCheckStatus Add PruneFunc Remove PruneFunc // Return is an error, or the StatusCode int ReturnChan chan interface{} }
HealthCheckWork is Work to run a HealthCheck
func (*HealthCheckWork) Return ¶
func (h *HealthCheckWork) Return(rthing interface{})
Return consumes a Work result and slides it downthe return channel
func (*HealthCheckWork) Work ¶
func (h *HealthCheckWork) Work() interface{}
Work executes the HealthCheck and returns HealthCheckResult or HealthCheckError
type JSONAccessLog ¶
type JSONAccessLog struct { Timestamp string `json:"timestamp"` Hostname string `json:"hostname"` RemoteAddress string `json:"remoteaddr"` User string `json:"user"` XForwardedFor string `json:"x-forwarded-for"` ClientIP string `json:"clientip"` Method string `json:"method"` Request string `json:"request"` Status string `json:"status"` Bytes string `json:"bytes"` UserAgent string `json:"user-agent"` Duration string `json:"duration"` Referer string `json:"referer"` Message string `json:"message"` RequestID string `json:"requestid"` Proto string `json:"proto"` TLSVersion string `json:"tlsversion"` // contains filtered or unexported fields }
JSONAccessLog is an AccessLog uberstruct for JSONifying log data
func (*JSONAccessLog) CommonLogFormat ¶
func (a *JSONAccessLog) CommonLogFormat(combined bool) string
CommonLogFormat will return the contents as a CLF-compatible string. If combined is set, a "combined" CLF is included (adds referer and user-agent)
func (*JSONAccessLog) RequestFiller ¶
func (a *JSONAccessLog) RequestFiller(r *http.Request)
RequestFiller adds request information to the AccessLog entry
func (*JSONAccessLog) Reset ¶
func (a *JSONAccessLog) Reset()
Reset will empty out the contents of the access log
func (*JSONAccessLog) ResponseFiller ¶
func (a *JSONAccessLog) ResponseFiller(endtime time.Time, duration time.Duration, responseCode int, responseLength int)
ResponseFiller adds response information to the AccessLog entry
type Member ¶
type Member struct { URL *url.URL Address string AZ string // contains filtered or unexported fields }
Member is an attribute struct to describe a Pool Member
type NoopResponseWriter ¶
type NoopResponseWriter struct {
// contains filtered or unexported fields
}
NoopResponseWriter is a hack to support a Response with a status and headers, but no body. This is almost never what you want. Really.
func NewNoopResponseWriter ¶
func NewNoopResponseWriter() NoopResponseWriter
NewNoopResponseWriter returns a NoopResponseWriter that you almost definitely do not want to use.
func (*NoopResponseWriter) Header ¶
func (n *NoopResponseWriter) Header() http.Header
Header returns an http.Header
func (*NoopResponseWriter) Write ¶
func (n *NoopResponseWriter) Write(bytes []byte) (int, error)
Write completely ignores whatever you've written, but lies and returns the size of whatever you wrote to it, and never an error
func (*NoopResponseWriter) WriteHeader ¶
func (n *NoopResponseWriter) WriteHeader(statusCode int)
WriteHeader changes the response code
type PageCache ¶ added in v1.3.0
type PageCache struct { Name string CacheSize int64 MaxItemSize int64 // MaxItemSize > 0 is *roughly* the largest "page" "body" that will be cached ItemExpiration time.Duration // contains filtered or unexported fields }
PageCache is a cache that is specific to caching responses
type Path ¶
type Path struct { // Name is an optional "name" for the path. Will be output in some logs. If not set, will use an index number Name string // Path is a URI prefix to match Path string // Absolute declares if Path should be absolute instead of as a prefix Absolute bool // Allow Allow string // Deny Deny string // Host is a hostname or hostname-pattern to restrict this Path too Host string // Hosts is a list of hostnames or hostname-patterns to restrict this Path too. // Will result in one actual Path per entry, which is almost always fine. Hosts []string // Methods is a list of HTTP methods to restrict this path to Methods []string // Headers is a list of HTTP Request headers to restrict this path to Headers []string // Handlers is an ordered list of http.Handlers to apply Handlers []string // Pool is an actual Pool to handle the proxying. Mutually exclusive with Finisher Pool string // Finisher is the final handler. Mutually exclusive with Pool Finisher string // CacheName is the name of the cache to use, and should match a CachePool CacheName string // RateLimit each IP to these many requests/second. Also must have the "RateLimiter" handler, or it will be appended to the chain RateLimit float64 // RateLimitPurge is a duration where a limit gets dumped RateLimitPurge time.Duration // RateLimitCollectOnly sets if the ratelimiter should only collect and log, versus enforce RateLimitCollectOnly bool // BodyByteLimit is the maximum number of bytes a Request.Body is allowed to be. It is poor form to set this unless the Path is terminated by // a finisher that will otherwise consume the Request.Body and possibly OOM and/or overuse disk space. BodyByteLimit int64 // Redirect is a special Finisher. "%1" may be used to optionally denote the request path. // e.g. Redirect http://somewhereelse.com%1 Redirect string // RedirectCode is an optional code to send as the redirect status RedirectCode int // RedirectHostMatch is a Perl-Compatible Regular Expression with grouping to apply to the Hostname, replacing $1,$2, etc. in “Redirect“ RedirectHostMatch string // ReplacePath is used to replace the requested path with the target path ReplacePath string // StripPrefix is used to replace the requested path with one sans prefix StripPrefix string // BrowserExclusions is a list of browsers disallowed down this path, based on best-effort analysis of request headers BrowserExclusions []string // ForbiddenPaths is a list of path prefixes that will result in a 403, while traversing this path ForbiddenPaths []string // Timeout is a path-specific override of how long a request and response may take on this path Timeout time.Duration // BasicAuthRealm is the name of the HTTP Auth Realm on this Path. Need not be unique. Should not be empty. BasicAuthRealm string // BasicAuthSource is a URL to specify where HTTP Basic Auth information should come from (file://). Setting this forces auth BasicAuthSource string // BasicAuthUsers is a list of usernames allowed on this Path. Default is "all" BasicAuthUsers []string // ErrorMessage is a static message to respond with, if this path is executed ErrorMessage string // ErrorCode is the HTTP response code that will be returned with ErrorMessage, IFF ErrorMessage is set. Defaults to StatusOK ErrorCode int // HMACSigned is set if the URL will be signed and should be verified. Various Options need too be set in order for this to work. HMACSigned bool // Options is a horrible, brittle map[string]interface{} that some handlers or finishers // use for per-path configuration. Avoid if possible. Options PathOptions }
Path is an extensible struct, detailing its configuration
type PathHandler ¶
type PathHandler struct { Path string Options PathOptions }
PathHandler is a wrapping struct to inject the Path name, and any PathOptions into the Context
type PathOptions ¶
type PathOptions map[string]interface{}
PathOptions is an MSI with a case-agnostic getter
func (*PathOptions) Get ¶
func (p *PathOptions) Get(key string) interface{}
Get returns an interface{} if *key* matches, otherwise nil
func (*PathOptions) GetBool ¶
func (p *PathOptions) GetBool(key string) bool
GetBool returns a bool value if *key* matches, otherwise false
func (*PathOptions) GetDuration ¶ added in v1.2.1
func (p *PathOptions) GetDuration(key string) (time.Duration, error)
GetDuration returns a Duration if *key* matches, otherwise zero-time
func (*PathOptions) GetInt64 ¶ added in v1.3.0
func (p *PathOptions) GetInt64(key string) (int64, error)
GetInt64 returns an int64 if *key* matches, otherwise zero
func (*PathOptions) GetString ¶
func (p *PathOptions) GetString(key string) string
GetString returns a string if *key* matches, otherwise empty string
func (*PathOptions) GetStringSlice ¶
func (p *PathOptions) GetStringSlice(key string) []string
GetStringSlice returns a []string if *key* matches, otherwise an empty []string
type PathReplacer ¶
PathReplacer is a wrapping struct to replace the Request path
type PathStripper ¶
type PathStripper struct {
Prefix string
}
PathStripper is a wrapping struct to remove the prefix from the Request path
type Pool ¶
type Pool struct { Config *PoolConfig // AddMember adds a URI to the loadbalancer. An error is returned if the URI doesn't parse properly AddMember func(string) error // RemoveMember removes a URI from the loadbalancer, but not from the member cache. // ErrNoSuchMemberError is returned if the requested member doesn't exist, // or another error if the URI provided doesn't parse properly. RemoveMember func(string) error // DeleteMember removes a URI from the entire Pool construct, // ErrNoSuchMemberError is returned if the requested member doesn't exist, // or another error if the URI provided doesn't parse properly. DeleteMember func(string) error // ListMembers returns a list of URIs for existing members ListMembers func() []*url.URL // contains filtered or unexported fields }
Pool is a list of like-minded destinations
func NewPool ¶ added in v1.5.0
func NewPool(conf *PoolConfig) *Pool
NewPool returns a new, minimal, unmaterialized pool with the attached config
func (*Pool) GetMember ¶
GetMember interacts with an internal cache, returning a Member from the cache or crafting a new one (and adding it to the cache)
func (*Pool) GetPool ¶
GetPool returns the materialized pool or an error. If the Pool has not been materialized, it does that.
func (*Pool) IsMaterialized ¶
IsMaterialized return boolean on whether the pool has been materialized or not
type PoolConfig ¶
type PoolConfig struct { // Name is what you'd like to call this Pool Name string // Members is a list of URIs you'd like in the pool Members []string // Buffered refers to whether you'd like buffer all the requests, to possibly retry them in the even of a Member failure Buffered bool // BufferedFails is the number of failures to accept before giving up BufferedFails int // RemoveHeaders is a list of pool-specific headers to remove RemoveHeaders []string // ConsistentHashing is mutually exclusive to Sticky, and enables automatic distributions ConsistentHashing bool // ConsistentHashSources is a list of "header", "cookie", or "request". // For "header" and "cookie", it is paired with ConsistentHashName to choose which key from those maps is used. // For "request" it is paired with ConsistentHashName to choose from one of "remoteaddr", "host", and "url". // ConsistentHashSources ***must be balanced with ConsistentHashNames***. ConsistentHashSources []string // ConsistentHashNames is a list that sets the request part, header, or cookie name to pull the value from. // ConsistentHashSources ***must be balanced with ConsistentHashSources***. ConsistentHashNames []string // Sticky is mutually exclusive to ConsistentHashing, and enables cookie-based session routing Sticky bool // StickyCookieName overrides the name of the cookie used to handle sticky sessions StickyCookieName string // StickyCookieType allows for the setting of cookie values to "plain", "hash", or "aes"-encrypted. // The value of Conf.GetString(ConfigKeysStickyCookie) will be the salt for "hash" as-is, or the // base64-encoded key for "aes". StickyCookieType string // StripPrefix removes the specified string from the front of a URL before processing. Dupes Path.StripPrefix StripPrefix string // HealthCheckDisabled determines whether or not to healthcheck the members. HealthCheckDisabled bool // Healthcheck is a URI to check for health. Anything other than a 200 is bad. HealthCheckURI string // HealthCheckShotgun will disable the adaptive healthcheck scheduler, and fire all of them every interval HealthCheckShotgun bool // HealthCheckErrorStatus is a string mapping to a const HealthCheckStatus HealthCheckErrorStatus string // ReplacePath is used to replace the requested path with the target path ReplacePath string // Prune removes members that fail healthcheck, until they pass again Prune bool // EC2Affinity specifies whether an EC2-aware JAR should prefer a same-AZ member if available EC2Affinity bool // Options is a horrible, brittle map[string]interface{} that some PoolManagers // use for per-pool configuration. Avoid if possible. Options PoolOptions }
PoolConfig is type exposing expected configuration for a pool, abstracted for passing around
type PoolID ¶
type PoolID struct {
Pool string
}
PoolID is a wrapping struct to inject the Pool name into the Context
type PoolManager ¶ added in v1.2.0
type PoolManager interface { Servers() []*url.URL ServeHTTP(w http.ResponseWriter, req *http.Request) ServerWeight(u *url.URL) (int, bool) RemoveServer(u *url.URL) error UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error NextServer() (*url.URL, error) Next() http.Handler }
PoolManager is an interface to encompass oxy/roundrobin and our chpool
type PoolMaterializer ¶ added in v1.5.0
PoolMaterializer is a function responsible for materializing a Pool
type PoolOptions ¶ added in v1.2.0
type PoolOptions map[string]interface{}
PoolOptions is an MSI with a case-agnostic getter
func (*PoolOptions) Get ¶ added in v1.2.0
func (p *PoolOptions) Get(key string) interface{}
Get returns an interface{} if *key* matches, otherwise nil
func (*PoolOptions) GetBool ¶ added in v1.2.0
func (p *PoolOptions) GetBool(key string) bool
GetBool returns a bool value if *key* matches, otherwise false
func (*PoolOptions) GetFloat64 ¶ added in v1.2.0
func (p *PoolOptions) GetFloat64(key string) float64
GetFloat64 returns a float64 if *key* matches, otherwise -1
func (*PoolOptions) GetInt ¶ added in v1.2.0
func (p *PoolOptions) GetInt(key string) int
GetInt returns an int if *key* matches, otherwise -1
func (*PoolOptions) GetString ¶ added in v1.2.0
func (p *PoolOptions) GetString(key string) string
GetString returns a string if *key* matches, otherwise empty string
func (*PoolOptions) GetStringSlice ¶ added in v1.2.0
func (p *PoolOptions) GetStringSlice(key string) []string
GetStringSlice returns a []string if *key* matches, otherwise an empty []string
type Pools ¶
type Pools struct { sync.RWMutex // Readers must RLock/RUnlock. Writers must Lock/Unlock // StopWatch will stop the monitoring of the pool members. StopWatch func() // contains filtered or unexported fields }
Pools is a goro-safe map of Pool objects, and if interval > 0, will also healthcheck pool members, managing them accordingly.
func BuildPools ¶
BuildPools unmarshalls the pools config, creates them, and updates the pool list ConfigPoolsHealthcheckInterval will set the healthcheck interval for pool members. Set to 0 to disable.
func NewPools ¶
NewPools creates a functioning Pools struct, initialized with the pools, and a healthcheck interval. Set the interval to 0 to disable healthchecks
type ProcessInfo ¶
ProcessInfo is used to track information about ourselves. All member functions are safe to use across goros
func NewProcessInfo ¶
func NewProcessInfo(pid int32) *ProcessInfo
NewProcessInfo returns an intialized ProcessInfo that has an interval set to 1 minute. Supply 0 as the pid to autodetect the running process' pid
func (*ProcessInfo) CPU ¶
func (p *ProcessInfo) CPU() float64
CPU returns the current value of the CPU tracker, as a percent of total
func (*ProcessInfo) Memory ¶
func (p *ProcessInfo) Memory() float64
Memory returns the current value of the process memory, as a percent of total
func (*ProcessInfo) SetInterval ¶
func (p *ProcessInfo) SetInterval(i time.Duration)
SetInterval changes(?) the interval at which CPU slices are taken for comparison.
func (*ProcessInfo) UpdateCPU ¶
func (p *ProcessInfo) UpdateCPU()
UpdateCPU loops while Ctx is valid, sampling our CPU usage every interval. This should generally only be called once, unless you know what you're doing
type ProxyResponseModifier ¶
ProxyResponseModifier is a type interface compatible with oxy/forward, to allow the proxied response to be modified at proxy-time, before the Handlers will see the response. This is of special importance for responses which need absolute mangling before a response is completed e.g. streaming/chunked responses
type ProxyResponseModifierChain ¶
type ProxyResponseModifierChain struct {
// contains filtered or unexported fields
}
ProxyResponseModifierChain is an encapsulating type to chain multiple ProxyResponseModifier funcs for sequential execution as a single ProxyResponseModifier
func (*ProxyResponseModifierChain) Add ¶
func (p *ProxyResponseModifierChain) Add(prm ProxyResponseModifier)
Add appends the provided ProxyResponseModifier to the ProxyResponseModifierChain
func (*ProxyResponseModifierChain) ToProxyResponseModifier ¶
func (p *ProxyResponseModifierChain) ToProxyResponseModifier() ProxyResponseModifier
ToProxyResponseModifier returns a closure ProxyResponseModifier that will sequentially execute each encapsulated ProxyResponseModifier, discontinuing and returning an error as soon as one is noticed
type RateLimiter ¶
RateLimiter is a wrapper around limiter.Limiter
func NewRateLimiter ¶
func NewRateLimiter(max float64, purgeDuration time.Duration) RateLimiter
NewRateLimiter returns a RateLimiter based on the specified max rps and purgeDuration
func NewRateLimiterCollector ¶
func NewRateLimiterCollector(max float64, purgeDuration time.Duration) RateLimiter
NewRateLimiterCollector returns a RateLimiter based on the specified max rps and purgeDuration
type S3Pool ¶
type S3Pool struct {
// contains filtered or unexported fields
}
S3Pool is an http.Handler that grabs a file from S3 and streams it back to the client
type StatusFinisher ¶
type StatusFinisher int
StatusFinisher is an abstracted type to dynamically provide Finishers of standard HTTP status codes
func (StatusFinisher) Finisher ¶
func (sf StatusFinisher) Finisher(w http.ResponseWriter, r *http.Request)
Finisher writes a response of the set HTTP status code and text
type SuiteMap ¶
SuiteMap is a map of TLS cipher suites, to their hex code
func NewSuiteMapFromCipherSuites ¶
func NewSuiteMapFromCipherSuites(cipherSuites []*tls.CipherSuite) SuiteMap
NewSuiteMapFromCipherSuites takes a []*CipherSuite and creates a SuiteMap from it
func (*SuiteMap) AllSuites ¶
AllSuites returns the hex codes for all of the cipher suites in an untrustable order
func (*SuiteMap) CipherListToSuites ¶
CipherListToSuites takes an ordered list of cipher suite names, and returns their hex codes in the same order
type TemplateError ¶
type TemplateError struct { // ErrorCode is the string value of the error ErrorCode string // ErrorMessage is an optional message the template may optionally render ErrorMessage string // RedirectURL is a URL the template is advised to redirect to RedirectURL string // RedirectSeconds is the number of seconds the template is advised to wait // before executing the RedirectURL RedirectSeconds int }
TemplateError is a static structure to pass into error-wrapping templates
type Timeout ¶
Timeout is a middleware that causes a 503 Service Unavailable message to be handed back if the timeout trips
Source Files ¶
- a_common.go
- access.go
- basicauth.go
- cache.go
- compression.go
- config.go
- cors.go
- crypto.go
- debug.go
- errors.go
- finishers.go
- handlers.go
- health.go
- healthprocess.go
- helpers.go
- hmac.go
- log.go
- macros.go
- paths.go
- pool.go
- pool_conhash.go
- pool_sticky.go
- poolconfig.go
- pools.go
- proxyresponsemodifier.go
- s3pool.go
- s3proxy.go
- taskscheduler.go
- tus.go
- update.go
- urlswitch.go
- version.go
- worker-http.go
- worker-zulip.go
- workers.go
- z_zMustBeLast.go
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package dictionary provides the Dictionary interface for abstraction, and a simple stringmap implementation called SimpleDict, used for macro definition and replacement.
|
Package dictionary provides the Dictionary interface for abstraction, and a simple stringmap implementation called SimpleDict, used for macro definition and replacement. |
Package plugins provides support for Yaegi-style http.Handler "plugins", for use in JAR.
|
Package plugins provides support for Yaegi-style http.Handler "plugins", for use in JAR. |
tests
|
|
Package watcher is used to keep an eye on file system events, and trigger actions when those events are of interest.
|
Package watcher is used to keep an eye on file system events, and trigger actions when those events are of interest. |