httpserver

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2016 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminWebsocketReadBufferSize  = 1024
	AdminWebsocketWriteBufferSize = 1024
)
View Source
const (
	// CloseStatus is status code set when closing client connections.
	CloseStatus = 3000
)

Variables

View Source
var DefaultConfig = &Config{}

DefaultConfig is Config initialized with default values for all fields.

View Source
var DefaultMuxOptions = MuxOptions{
	HandlerFlags:  HandlerRawWS | HandlerSockJS | HandlerAPI | HandlerAdmin,
	SockjsOptions: sockjs.DefaultOptions,
}

DefaultMuxOptions contain default SockJS options.

Functions

func DefaultMux

func DefaultMux(s *HTTPServer, muxOpts MuxOptions) *http.ServeMux

DefaultMux returns a mux including set of default handlers for Centrifugo server.

func HTTPServerConfigure

func HTTPServerConfigure(setter config.Setter) error

func HTTPServerPlugin

func HTTPServerPlugin(n *node.Node, getter config.Getter) (server.Server, error)

func New

func New(n *node.Node, config *Config) (server.Server, error)

func NewSockJSHandler

func NewSockJSHandler(s *HTTPServer, sockjsPrefix string, sockjsOpts sockjs.Options) http.Handler

NewSockJSHandler returns SockJS handler bind to sockjsPrefix url prefix. SockJS handler has several handlers inside responsible for various tasks according to SockJS protocol.

Types

type Config

type Config struct {

	// Web enables admin web interface.
	Web bool `json:"web"`
	// WebPath
	WebPath string `json:"web_path"`

	// HTTPAddress
	HTTPAddress string `json:"http_address"`
	// HTTPPrefix
	HTTPPrefix string `json:"http_prefix"`
	// HTTPPort
	HTTPPort string `json:"http_port"`
	// HTTPAdminPort
	HTTPAdminPort string `json:"http_admin_port"`
	// HTTPAPIPort
	HTTPAPIPort string `json:"http_api_port"`

	// SSL enables builtin https server.
	SSL bool `json:"ssl"`
	// SSLCert is path to SSL certificate file.
	SSLCert string `json:"ssl_cert"`
	// SSLKey is path to SSL key file.
	SSLKey string `json:"ssl_key"`

	// SockjsURL is a custom SockJS library url to use in iframe transports.
	SockjsURL string `json:"sockjs_url"`

	// SockjsHeartbeatDelay allows to specify custom SockJS server to client heartbeat interval.
	// Starting from Centrifugo 1.6.0 we don't use it (i.e. set it 0) as we send pings from
	// client to server. But if someone wants old behaviour then it's possible to turn off ping
	// on client side and set this option to something reasonable (25 seconds for example).
	SockjsHeartbeatDelay int `json:"sockjs_heartbeat_delay"`

	// WebsocketCompression allows to enable websocket permessage-deflate
	// compression support for raw websocket connections. It does not guarantee
	// that compression will be used - i.e. it only says that Centrifugo will
	// try to negotiate it with client.
	WebsocketCompression bool `json:"websocket_compression"`

	// WebsocketCompressionMinSize allows to set minimal limit in bytes for message to use
	// compression when writing it into client connection. By default it's 0 - i.e. all messages
	// will be compressed when WebsocketCompression enabled and compression negotiated with client.
	WebsocketCompressionMinSize int `json:"websocket_compression_min_size"`

	// WebsocketReadBufferSize is a parameter that is used for raw websocket Upgrader.
	// If set to zero reasonable default value will be used.
	WebsocketReadBufferSize int `json:"websocket_read_buffer_size"`

	// WebsocketWriteBufferSize is a parameter that is used for raw websocket Upgrader.
	// If set to zero reasonable default value will be used.
	WebsocketWriteBufferSize int `json:"websocket_write_buffer_size"`
}

Config contains Application configuration options.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates config and returns error if problems found

type HTTPServer

type HTTPServer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*HTTPServer) APIHandler

func (s *HTTPServer) APIHandler(w http.ResponseWriter, r *http.Request)

APIHandler is responsible for receiving API commands over HTTP.

func (*HTTPServer) AdminWebsocketHandler

func (s *HTTPServer) AdminWebsocketHandler(w http.ResponseWriter, r *http.Request)

AdminWebsocketHandler handles admin websocket connections.

func (*HTTPServer) AuthHandler

func (s *HTTPServer) AuthHandler(w http.ResponseWriter, r *http.Request)

AuthHandler allows to get admin web interface token.

func (*HTTPServer) Logged

func (s *HTTPServer) Logged(h http.Handler) http.Handler

Logged middleware logs request.

func (*HTTPServer) RawWebsocketHandler

func (s *HTTPServer) RawWebsocketHandler(w http.ResponseWriter, r *http.Request)

RawWebsocketHandler called when new client connection comes to raw Websocket endpoint.

func (*HTTPServer) Run

func (s *HTTPServer) Run() error

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown() error

func (*HTTPServer) WrapShutdown

func (s *HTTPServer) WrapShutdown(h http.Handler) http.Handler

WrapShutdown will return an http Handler. If Application in shutdown it will return http.StatusServiceUnavailable.

type HandlerFlag

type HandlerFlag int

HandlerFlag is a bit mask of handlers that must be enabled in mux.

const (
	// HandlerRawWS enables Raw Websocket handler.
	HandlerRawWS HandlerFlag = 1 << iota
	// HandlerSockJS enables SockJS handler.
	HandlerSockJS
	// HandlerAPI enables API handler.
	HandlerAPI
	// HandlerAdmin enables admin handlers - admin websocket, web interface endpoints.
	HandlerAdmin
	// HandlerDebug enables debug handlers.
	HandlerDebug
)

func (HandlerFlag) String

func (flags HandlerFlag) String() string

type MuxOptions

type MuxOptions struct {
	Prefix        string
	Admin         bool
	Web           bool
	WebPath       string
	WebFS         http.FileSystem
	SockjsOptions sockjs.Options
	HandlerFlags  HandlerFlag
}

MuxOptions contain various options for DefaultMux.

Jump to

Keyboard shortcuts

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