Documentation ¶
Overview ¶
Package http provides a registration interface for http services
Index ¶
- Variables
- func AddAuthFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *AuthConfig)
- func AddHTTPFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *Config)
- func AddTemplateFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *TemplateConfig)
- func AfterEpoch(t time.Time) bool
- func AuthHelp(prefix string) string
- func CtxGetAuth(ctx context.Context) interface{}
- func CtxGetUser(ctx context.Context) (string, bool)
- func CtxSetUser(ctx context.Context, value string) context.Context
- func GetTemplate(tmpl string) (*template.Template, error)
- func Help(prefix string) string
- func IsAuthenticated(r *http.Request) bool
- func IsUnixSocket(r *http.Request) bool
- func NewBaseContext(ctx context.Context, url string) func(l net.Listener) context.Context
- func PublicURL(r *http.Request) string
- func TemplateHelp(prefix string) string
- type AuthConfig
- type Config
- type CustomAuthFn
- type LoggedBasicAuth
- type Middleware
- func MiddlewareAuthBasic(user, pass, realm, salt string) Middleware
- func MiddlewareAuthCertificateUser() Middleware
- func MiddlewareAuthCustom(fn CustomAuthFn, realm string, userFromContext bool) Middleware
- func MiddlewareAuthHtpasswd(path, realm string) Middleware
- func MiddlewareCORS(allowOrigin string) Middleware
- func MiddlewareStripPrefix(prefix string) Middleware
- type Option
- type Server
- type TemplateConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMinTLSVersion - hard coded errors, allowing for easier testing ErrInvalidMinTLSVersion = errors.New("invalid value for --min-tls-version") // ErrTLSBodyMismatch - hard coded errors, allowing for easier testing ErrTLSBodyMismatch = errors.New("need both TLSCertBody and TLSKeyBody to use TLS") // ErrTLSFileMismatch - hard coded errors, allowing for easier testing ErrTLSFileMismatch = errors.New("need both --cert and --key to use TLS") // ErrTLSParseCA - hard coded errors, allowing for easier testing ErrTLSParseCA = errors.New("unable to parse client certificate authority") )
var Assets embed.FS
Assets holds the embedded filesystem for the default template
Functions ¶
func AddAuthFlagsPrefix ¶
func AddAuthFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *AuthConfig)
AddAuthFlagsPrefix adds flags to the flag set for AuthConfig
func AddHTTPFlagsPrefix ¶
AddHTTPFlagsPrefix adds flags for the httplib
func AddTemplateFlagsPrefix ¶
func AddTemplateFlagsPrefix(flagSet *pflag.FlagSet, prefix string, cfg *TemplateConfig)
AddTemplateFlagsPrefix for the templating functionality
func AfterEpoch ¶
AfterEpoch returns the time since the epoch for the given time
func AuthHelp ¶
AuthHelp returns text describing the http authentication to add to the command help.
func CtxGetAuth ¶
CtxGetAuth is a wrapper over the private Auth context key
func CtxGetUser ¶
CtxGetUser is a wrapper over the private User context key
func CtxSetUser ¶
CtxSetUser is a test helper that injects a User value into context
func GetTemplate ¶
GetTemplate returns the HTML template for serving directories via HTTP/WebDAV
func IsAuthenticated ¶
IsAuthenticated checks if this request was authenticated via a middleware
func IsUnixSocket ¶
IsUnixSocket checks if the request was received on a unix socket, used to skip auth & CORS
func NewBaseContext ¶
NewBaseContext initializes the context for all requests, adding info for use in middleware and handlers
func TemplateHelp ¶
TemplateHelp returns a string that describes how to use a custom template
Types ¶
type AuthConfig ¶
type AuthConfig struct { HtPasswd string // htpasswd file - if not provided no authentication is done Realm string // realm for authentication BasicUser string // single username for basic auth if not using Htpasswd BasicPass string // password for BasicUser Salt string // password hashing salt CustomAuthFn CustomAuthFn `json:"-"` // custom Auth (not set by command line flags) }
AuthConfig contains options for the http authentication
func DefaultAuthCfg ¶
func DefaultAuthCfg() AuthConfig
DefaultAuthCfg returns a new config which can be customized by command line flags
func (*AuthConfig) AddFlagsPrefix ¶
func (cfg *AuthConfig) AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string)
AddFlagsPrefix adds flags to the flag set for AuthConfig
type Config ¶
type Config struct { ListenAddr []string // Port to listen on BaseURL string // prefix to strip from URLs ServerReadTimeout time.Duration // Timeout for server reading data ServerWriteTimeout time.Duration // Timeout for server writing data MaxHeaderBytes int // Maximum size of request header TLSCert string // Path to TLS PEM key (concatenation of certificate and CA certificate) TLSKey string // Path to TLS PEM Private key TLSCertBody []byte // TLS PEM key (concatenation of certificate and CA certificate) body, ignores TLSCert TLSKeyBody []byte // TLS PEM Private key body, ignores TLSKey ClientCA string // Client certificate authority to verify clients with MinTLSVersion string // MinTLSVersion contains the minimum TLS version that is acceptable. AllowOrigin string // AllowOrigin sets the Access-Control-Allow-Origin header }
Config contains options for the http Server
type CustomAuthFn ¶
CustomAuthFn if used will be used to authenticate user, pass. If an error is returned then the user is not authenticated.
If a non nil value is returned then it is added to the context under the key
type LoggedBasicAuth ¶
LoggedBasicAuth simply wraps the goauth.BasicAuth struct
func NewLoggedBasicAuthenticator ¶
func NewLoggedBasicAuthenticator(realm string, secrets goauth.SecretProvider) *LoggedBasicAuth
NewLoggedBasicAuthenticator instantiates a new instance of LoggedBasicAuthenticator
type Middleware ¶
Middleware function signature required by chi.Router.Use()
func MiddlewareAuthBasic ¶
func MiddlewareAuthBasic(user, pass, realm, salt string) Middleware
MiddlewareAuthBasic instantiates middleware that authenticates for a single user
func MiddlewareAuthCertificateUser ¶
func MiddlewareAuthCertificateUser() Middleware
MiddlewareAuthCertificateUser instantiates middleware that extracts the authenticated user via client certificate common name
func MiddlewareAuthCustom ¶
func MiddlewareAuthCustom(fn CustomAuthFn, realm string, userFromContext bool) Middleware
MiddlewareAuthCustom instantiates middleware that authenticates using a custom function
func MiddlewareAuthHtpasswd ¶
func MiddlewareAuthHtpasswd(path, realm string) Middleware
MiddlewareAuthHtpasswd instantiates middleware that authenticates against the passed htpasswd file
func MiddlewareCORS ¶
func MiddlewareCORS(allowOrigin string) Middleware
MiddlewareCORS instantiates middleware that handles basic CORS protections for rcd
func MiddlewareStripPrefix ¶
func MiddlewareStripPrefix(prefix string) Middleware
MiddlewareStripPrefix instantiates middleware that removes the BaseURL from the path
type Option ¶
type Option func(*Server)
Option allows customizing the server
func WithAuth ¶
func WithAuth(cfg AuthConfig) Option
WithAuth option initializes the appropriate auth middleware
func WithConfig ¶
WithConfig option applies the Config to the server, overriding defaults
func WithTemplate ¶
func WithTemplate(cfg TemplateConfig) Option
WithTemplate option allows the parsing of a template
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server contains info about the running http server
func NewServer ¶
NewServer instantiates a new http server using provided listeners and options This function is provided if the default http server does not meet a services requirements and should not generally be used A http server can listen using multiple listeners. For example, a listener for port 80, and a listener for port 443. tlsListeners are ignored if opt.TLSKey is not provided
func (*Server) HTMLTemplate ¶
HTMLTemplate returns the parsed template, if WithTemplate option was passed.
type TemplateConfig ¶
type TemplateConfig struct {
Path string
}
TemplateConfig for the templating functionality
func DefaultTemplateCfg ¶
func DefaultTemplateCfg() TemplateConfig
DefaultTemplateCfg returns a new config which can be customized by command line flags
func (*TemplateConfig) AddFlagsPrefix ¶
func (cfg *TemplateConfig) AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string)
AddFlagsPrefix for the templating functionality