httpserver

package
v0.0.0-...-56739e2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

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

HTTPServerConfigure is a Configurator func for default Centrifugo http server.

func HTTPServerPlugin

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

HTTPServerPlugin is a plugin that returns HTTPServer.

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"`

	// SSLAutocert enables automatic certificate receive from ACME provider.
	SSLAutocert bool `json:"ssl_autocert"`
	// SSLAutocertHostWhitelist is a slice of host names ACME Manager is allowed to respond to.
	SSLAutocertHostWhitelist []string `json:"ssl_autocert_host_whitelist"`
	// SSLAutocertCacheDir is a folder to cache certificates from ACME provider.
	SSLAutocertCacheDir string `json:"ssl_autocert_cache_dir"`
	// SSLAutocertEmail is a contact email address to notify about problems with certificates.
	SSLAutocertEmail string `json:"ssl_autocert_email"`
	// SSLAutocertForceRSA forces autocert manager generate certificates with 2048-bit RSA keys.
	SSLAutocertForceRSA bool `json:"ssl_autocert_force_rsa"`
	// SSLAutocertServerName allows to set ServerName for ClientHelloInfo object if it's empty.
	// This can be useful to deal with old browsers without SNI support -
	// see https://github.com/centrifugal/centrifugo/issues/144#issuecomment-279393819
	SSLAutocertServerName string `json:"ssl_autocert_server_name"`

	// 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"`

	// WebsocketCompressionLevel sets a level for websocket compression.
	// See posiible value description at https://golang.org/pkg/compress/flate/#NewWriter
	WebsocketCompressionLevel int `json:"websocket_compression_level"`

	// 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
}

HTTPServer is a default builtin Centrifugo server.

func New

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

New initializes HTTPServer.

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

Run runs HTTPServer.

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown() error

Shutdown shuts down server.

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