Documentation
¶
Overview ¶
Package api middleware: request-scoped HTTP middlewares used by the REST router.
Index ¶
Constants ¶
const ( // None defines to run http server only None sslMode = iota // Static defines to run both https and http server. Redirect http to https Static // Auto defines to run both https and http server. Redirect http to https. Https server with autocert support Auto )
Variables ¶
This section is empty.
Functions ¶
func ParseTrustedProxies ¶ added in v1.16.2
ParseTrustedProxies parses a list of trusted-proxy entries into CIDRs. Each entry may be a CIDR (e.g. 172.16.0.0/12) or a bare IP (treated as a single host). Blank entries are skipped; a malformed entry is a hard error so a typo can't silently disable proxy trust.
func TrustsAnyPeer ¶ added in v1.16.2
TrustsAnyPeer reports whether the trusted-proxy list contains a catch-all (0.0.0.0/0 or ::/0), which trusts forwarding headers from every client and re-opens the IP-spoofing bypass.
func URLKey ¶
URLKey gets url from request to use it as cache key admins will have different keys in order to prevent leak of admin-only data to regular users
func URLKeyWithUser ¶
URLKeyWithUser gets url from request to use it as cache key and attaching user ID admins will have different keys in order to prevent leak of admin-only data to regular users
Types ¶
type LoadingCache ¶
type LoadingCache interface {
Get(key lcw.Key, fn func() ([]byte, error)) (data []byte, err error) // load from cache if found or put to cache and return
Flush(req lcw.FlusherRequest) // evict matched records
Close() error
}
LoadingCache defines interface for caching
type Migrator ¶
type Migrator struct {
Cache LoadingCache
NativeImporter migrator.Importer
DisqusImporter migrator.Importer
WordPressImporter migrator.Importer
CommentoImporter migrator.Importer
NativeExporter migrator.Exporter
URLMapperMaker migrator.MapperMaker
KeyStore KeyStore
// contains filtered or unexported fields
}
Migrator rest with import and export controllers
type Rest ¶
type Rest struct {
Version string
DataService *service.DataStore
Authenticator *auth.Service
Cache LoadingCache
ImageProxy *proxy.Image
CommentFormatter *store.CommentFormatter
Migrator *Migrator
NotifyService *notify.Service
TelegramService telegramService
ImageService *image.Service
AnonVote bool
WebRoot string
WebFS fs.FS
RemarkURL string
DemoSiteID string // site the demo pages under /web show, the first configured one
ReadOnlyAge int
TrustedProxies []*net.IPNet // reverse-proxy networks whose forwarding headers (X-Real-IP, X-Forwarded-For, ...) are trusted
ScoreThresholds struct {
Low int
Critical int
}
UpdateLimiter float64
EmailNotifications bool
TelegramNotifications bool
EmojiEnabled bool
SimpleView bool
ProxyCORS bool
SendJWTHeader bool
AllowedAncestors []string // sets Content-Security-Policy "frame-ancestors ..."
SubscribersOnly bool
DisableSignature bool // prevent signature from being added to headers
DisableFancyTextFormatting bool // disables SmartyPants in the comment text rendering of the posted comments
ExternalImageProxy bool
SSLConfig SSLConfig
// contains filtered or unexported fields
}
Rest is a rest access server