Back to

Package caddyesi

Latest Go to latest

The latest major version is .

Published: Feb 3, 2019 | License: Apache-2.0 | Module:



const DefaultMaxBodySize uint64 = 5 << 20

DefaultMaxBodySize the body size of a retrieved request to a resource. 5 MB is a lot of text.

const DefaultOnError = `Resource not available`

DefaultOnError default error message when a backend service cannot be requested. Only when config value on_error in Caddyfile has not been supplied.

const DefaultTimeOut = 20 * time.Second

DefaultTimeOut to a backend resource

func PluginSetup

func PluginSetup(c *caddy.Controller) error

PluginSetup used internally by Caddy to set up this middleware

type Middleware

type Middleware struct {
	Group singleflight.Group
	// Root the Server root
	Root string
	//FileSys  jails the requests to site root with a mock file system
	FileSys http.FileSystem
	// Next HTTP handler in the chain
	Next httpserver.Handler

	// PathConfigs The list of Tag configurations for each path prefix and theirs
	// caches.
	// contains filtered or unexported fields

Middleware implements the Tag tag middleware

func (*Middleware) ServeHTTP

func (mw *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP implements the http.Handler interface.

type PathConfig

type PathConfig struct {
	// Scope sets the base path to match used as path prefix
	Scope string

	// MaxBodySize defaults to 5MB and limits the size of the returned body from a
	// backend resource.
	MaxBodySize uint64
	// Timeout global. Time when a request to a source should be canceled.
	// Default value from the constant DefaultTimeOut.
	Timeout time.Duration
	// TTL global time-to-live in the storage backend for Tag data. Defaults to
	// zero, caching globally disabled until an Tag tag or this configuration
	// value contains the TTL attribute.
	TTL time.Duration
	// CmdHeaderName if set allows to execute certain maintenance functions to
	// e.g. purge the cache. For security reasons an empty string means, feature
	// has been disabled.
	CmdHeaderName string

	// PageIDSource defines a slice of possible parameters which gets extracted
	// from the http.Request object. All these parameters will be used to
	// extract the values and calculate a unique hash for the current requested
	// page to identify the already parsed Tag tags in the cache.
	PageIDSource []string
	// AllowedMethods list of all benchIsResponseAllowed methods, defaults to GET
	AllowedMethods []string
	// OnError gets output when a request to a backend service fails.
	OnError []byte
	// LogFile where to write the log output? Either any file name or stderr or
	// stdout. If empty logging disabled.
	LogFile string

	// LogLevel can have the values info, debug, fatal. If empty logging disabled.
	LogLevel string
	// Log gets set up during setup
	Log log.Logger
	// contains filtered or unexported fields

PathConfig per path prefix

func NewPathConfig

func NewPathConfig() *PathConfig

NewPathConfig creates a configuration for a unique path prefix and initializes the internal maps.

func (*PathConfig) ESITagsByRequest

func (pc *PathConfig) ESITagsByRequest(r *http.Request) (pageID uint64, t esitag.Entities)

ESITagsByRequest selects in the ServeHTTP function all ESITags identified by their pageIDs. Returns a nil t when the entry does not exists.

func (*PathConfig) IsRequestAllowed

func (pc *PathConfig) IsRequestAllowed(r *http.Request) bool

IsRequestAllowed decides if a request should be processed based on the request method. The benchIsResponseAllowed response content-type is text only.

func (*PathConfig) String

func (pc *PathConfig) String() string

String used for log information output

func (*PathConfig) UpsertESITags

func (pc *PathConfig) UpsertESITags(pageID uint64, entities esitag.Entities)

UpsertESITags processes each Tag entity to update their default values with the supplied global PathConfig value. Then inserts the Tag entities with its associated page ID in the internal Tag cache. These writes to esitag.Entity happens in a locked environment. So there should be no race condition.

type PathConfigs

type PathConfigs []*PathConfig

PathConfigs contains the configuration for each path prefix

func (PathConfigs) ConfigForPath

func (pc PathConfigs) ConfigForPath(r *http.Request) *PathConfig

ConfigForPath selects in the ServeHTTP function the config for a path.

func (PathConfigs) String

func (pc PathConfigs) String() string

String prints debug information. Very slow ...

type ResourceItem

type ResourceItem struct {
	// Alias can have any name which gets used in an Tag tag and refers to the
	// connection to a resource.
	Alias string `xml:"alias" json:"alias"`
	// URL defines the authentication and target to a resource. If an URL
	// contains the name of an Alias then the URl data from that alias will be
	// copied into this URL field.
	URL string `xml:"url" json:"url"`
	// Query contains mostly a SQL query which runs as a prepared statement so you
	// must use the question mark or any other placeholder.
	Query string `xml:"query,omitempty" json:"query"`

ResourceItem defines a single configuration item.

func NewResourceItem

func NewResourceItem(url string, aliasQuery ...string) *ResourceItem

NewResourceItem creates a new resource item. Supports up to 3 arguments.

type ResourceItems

type ResourceItems []*ResourceItem

ResourceItems as list of multiple configuration items. This type has internal helper functions.

func UnmarshalResourceItems

func UnmarshalResourceItems(fileName string) (itms ResourceItems, err error)

UnmarshalResourceItems runs during Caddy setup and reads the extended resource configuration file. This file contains the alias name, the URL where the resource can be accessed and how and also in case of databases the query. Supported formats are for now XML and JSON. XML has the advantage of using CDATA and comments where in JSON you need to encode the strings properly. For security reasons you must store this fileName in a non-webserver accessible directory.

func (ResourceItems) MustToXML

func (ci ResourceItems) MustToXML() string

MustToXML transforms the object into a strings and panics on error. Only used in testing.

func (ResourceItems) WriteTo

func (ci ResourceItems) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the XML into w and may return an error. It returns always zero bytes written :-(.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier