libwebsocketd

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2021 License: BSD-2-Clause Imports: 21 Imported by: 15

Documentation

Index

Constants

View Source
const (
	LogDebug = iota
	LogTrace
	LogAccess
	LogInfo
	LogError
	LogFatal

	LogNone    = 126
	LogUnknown = 127
)
View Source
const (
	License = license
)

Variables

View Source
var ConsoleContent = defaultConsoleContent
View Source
var ForkNotAllowedError = errors.New("too many forks active")
View Source
var ScriptNotFoundError = errors.New("script not found")

Functions

func PipeEndpoints added in v0.2.9

func PipeEndpoints(e1, e2 Endpoint)

func Timestamp

func Timestamp() string

Types

type AssocPair

type AssocPair struct {
	Key   string
	Value string
}

type Config

type Config struct {
	// base initiaization fields
	StartupTime    time.Time // Server startup time (used for dev console caching).
	CommandName    string    // Command to execute.
	CommandArgs    []string  // Additional args to pass to command.
	ServerSoftware string    // Value to pass to SERVER_SOFTWARE environment variable (e.g. websocketd/1.2.3).
	CloseMs        uint      // Milliseconds to start sending signals

	HandshakeTimeout time.Duration // time to finish handshake (default 1500ms)

	// settings
	Binary         bool     // Use binary communication (send data in chunks they are read from process)
	ReverseLookup  bool     // Perform reverse DNS lookups on hostnames (useful, but slower).
	Ssl            bool     // websocketd works with --ssl which means TLS is in use
	ScriptDir      string   // Base directory for websocket scripts.
	UsingScriptDir bool     // Are we running with a script dir.
	StaticDir      string   // If set, static files will be served from this dir over HTTP.
	CgiDir         string   // If set, CGI scripts will be served from this dir over HTTP.
	DevConsole     bool     // Enable dev console. This disables StaticDir and CgiDir.
	AllowOrigins   []string // List of allowed origin addresses for websocket upgrade.
	SameOrigin     bool     // If set, requires websocket upgrades to be performed from same origin only.
	Headers        []string
	HeadersWs      []string
	HeadersHTTP    []string

	// created environment
	Env       []string // Additional environment variables to pass to process ("key=value").
	ParentEnv []string // Variables kept from os.Environ() before sanitizing it for subprocess.
}

type Endpoint

type Endpoint interface {
	StartReading()
	Terminate()
	Output() chan []byte
	Send([]byte) bool
}

type LaunchedProcess

type LaunchedProcess struct {
	// contains filtered or unexported fields
}

type LogFunc

type LogFunc func(logScope *LogScope, level LogLevel, levelName string, category string, msg string, args ...interface{})

type LogLevel

type LogLevel int

func LevelFromString added in v0.2.9

func LevelFromString(s string) LogLevel

type LogScope

type LogScope struct {
	Parent     *LogScope   // Parent scope
	MinLevel   LogLevel    // Minimum log level to write out.
	Mutex      *sync.Mutex // Should be shared across all LogScopes that write to the same destination.
	Associated []AssocPair // Additional data associated with scope
	LogFunc    LogFunc
}

func RootLogScope

func RootLogScope(minLevel LogLevel, logFunc LogFunc) *LogScope

func (*LogScope) Access

func (l *LogScope) Access(category string, msg string, args ...interface{})

func (*LogScope) Associate

func (l *LogScope) Associate(key string, value string)

func (*LogScope) Debug

func (l *LogScope) Debug(category string, msg string, args ...interface{})

func (*LogScope) Error

func (l *LogScope) Error(category string, msg string, args ...interface{})

func (*LogScope) Fatal

func (l *LogScope) Fatal(category string, msg string, args ...interface{})

func (*LogScope) Info

func (l *LogScope) Info(category string, msg string, args ...interface{})

func (*LogScope) NewLevel

func (parent *LogScope) NewLevel(logFunc LogFunc) *LogScope

func (*LogScope) Trace

func (l *LogScope) Trace(category string, msg string, args ...interface{})

type ProcessEndpoint

type ProcessEndpoint struct {
	// contains filtered or unexported fields
}

func NewProcessEndpoint

func NewProcessEndpoint(process *LaunchedProcess, bin bool, log *LogScope) *ProcessEndpoint

func (*ProcessEndpoint) Output

func (pe *ProcessEndpoint) Output() chan []byte

func (*ProcessEndpoint) Send

func (pe *ProcessEndpoint) Send(msg []byte) bool

func (*ProcessEndpoint) StartReading added in v0.2.9

func (pe *ProcessEndpoint) StartReading()

func (*ProcessEndpoint) Terminate

func (pe *ProcessEndpoint) Terminate()

type RemoteInfo added in v0.2.9

type RemoteInfo struct {
	Addr, Host, Port string
}

RemoteInfo holds information about remote http client

func GetRemoteInfo added in v0.2.9

func GetRemoteInfo(remote string, doLookup bool) (*RemoteInfo, error)

GetRemoteInfo creates RemoteInfo structure and fills its fields appropriately

type URLInfo

type URLInfo struct {
	ScriptPath string
	PathInfo   string
	FilePath   string
}

URLInfo - structure carrying information about current request and it's mapping to filesystem

func GetURLInfo added in v0.2.9

func GetURLInfo(path string, config *Config) (*URLInfo, error)

GetURLInfo is a function that parses path and provides URL info according to libwebsocketd.Config fields

type WebSocketEndpoint

type WebSocketEndpoint struct {
	// contains filtered or unexported fields
}

func NewWebSocketEndpoint

func NewWebSocketEndpoint(ws *websocket.Conn, bin bool, log *LogScope) *WebSocketEndpoint

func (*WebSocketEndpoint) Output

func (we *WebSocketEndpoint) Output() chan []byte

func (*WebSocketEndpoint) Send

func (we *WebSocketEndpoint) Send(msg []byte) bool

func (*WebSocketEndpoint) StartReading added in v0.2.9

func (we *WebSocketEndpoint) StartReading()

func (*WebSocketEndpoint) Terminate

func (we *WebSocketEndpoint) Terminate()

type WebsocketdHandler added in v0.2.9

type WebsocketdHandler struct {
	Id string
	*RemoteInfo
	*URLInfo // TODO: I cannot find where it's used except in one single place as URLInfo.FilePath
	Env      []string
	// contains filtered or unexported fields
}

WebsocketdHandler is a single request information and processing structure, it handles WS requests out of all that daemon can handle (static, cgi, devconsole)

func NewWebsocketdHandler added in v0.2.9

func NewWebsocketdHandler(s *WebsocketdServer, req *http.Request, log *LogScope) (wsh *WebsocketdHandler, err error)

NewWebsocketdHandler constructs the struct and parses all required things in it...

type WebsocketdServer added in v0.2.9

type WebsocketdServer struct {
	Config *Config
	Log    *LogScope
	// contains filtered or unexported fields
}

WebsocketdServer presents http.Handler interface for requests libwebsocketd is handling.

func NewWebsocketdServer added in v0.2.9

func NewWebsocketdServer(config *Config, log *LogScope, maxforks int) *WebsocketdServer

NewWebsocketdServer creates WebsocketdServer struct with pre-determined config, logscope and maxforks limit

func (*WebsocketdServer) ServeHTTP added in v0.2.9

func (h *WebsocketdServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP muxes between WebSocket handler, CGI handler, DevConsole, Static HTML or 404.

func (*WebsocketdServer) TellURL added in v0.2.9

func (h *WebsocketdServer) TellURL(scheme, host, path string) string

TellURL is a helper function that changes http to https or ws to wss in case if SSL is used

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL