Documentation ¶
Overview ¶
Package server provides REST and Web server routing, request handling and logging.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
This program is free software: you can redistribute it and/or modify it under Version 3 of the GNU Affero General Public License (the "AGPL"): <https://docs.photoprism.app/license/agpl> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. The AGPL is supplemented by our Trademark and Brand Guidelines, which describe how our Brand Assets may be used: <https://www.photoprism.app/trademark>
Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>
Index ¶
- Constants
- Variables
- func AutoTLS(conf *config.Config) (*autocert.Manager, error)
- func Logger() gin.HandlerFunc
- func Recovery() gin.HandlerFunc
- func Register(name string, init func(router *gin.Engine, conf *config.Config) error)
- func Start(ctx context.Context, conf *config.Config)
- func StartAutoTLS(s *http.Server, m *autocert.Manager, conf *config.Config)
- func StartHttp(s *http.Server, l net.Listener)
- func StartTLS(s *http.Server, httpsCert, privateKey string)
- func WebDAV(filePath string, router *gin.RouterGroup, conf *config.Config)
- func WebDAVAbortServerError(c *gin.Context)
- func WebDAVAbortUnauthorized(c *gin.Context)
- func WebDAVAuth(conf *config.Config) gin.HandlerFunc
- func WebDAVAuthSession(c *gin.Context, authToken string) (sess *entity.Session, user *entity.User, sid string, cached bool)
- func WebDAVFileName(request *http.Request, router *gin.RouterGroup, conf *config.Config) (fileName string)
- func WebDAVSetFavoriteFlag(fileName string)
- func WebDAVSetFileMtime(fileName string, mtimeUnix int64)
- type Extension
- type Extensions
Constants ¶
const ( MethodHead = "HEAD" MethodGet = "GET" MethodPut = "PUT" MethodPost = "POST" MethodPatch = "PATCH" MethodDelete = "DELETE" MethodOptions = "OPTIONS" MethodMkcol = "MKCOL" MethodCopy = "COPY" MethodMove = "MOVE" MethodLock = "LOCK" MethodUnlock = "UNLOCK" MethodPropfind = "PROPFIND" MethodProppatch = "PROPPATCH" )
const ( WebDAVOriginals = "/originals" WebDAVImport = "/import" )
Variables ¶
var APIv1 *gin.RouterGroup
var Api = func(conf *config.Config) gin.HandlerFunc { return func(c *gin.Context) { if c.GetHeader(header.XAuthToken) != "" { c.Writer.Header().Add(header.Vary, header.XAuthToken) } else if c.GetHeader(header.XSessionID) != "" { c.Writer.Header().Add(header.Vary, header.XSessionID) } if origin := conf.CORSOrigin(); origin != "" { c.Header(header.AccessControlAllowOrigin, origin) if c.Request.Method == http.MethodOptions { c.Header(header.AccessControlAllowHeaders, conf.CORSHeaders()) c.Header(header.AccessControlAllowMethods, conf.CORSMethods()) c.Header(header.AccessControlMaxAge, header.DefaultAccessControlMaxAge) } } } }
Api is a middleware that sets additional response headers when serving REST API requests.
var BasicAuthRealm = "Basic realm=\"WebDAV Authorization Required\""
var Security = func(conf *config.Config) gin.HandlerFunc { return func(c *gin.Context) { if header.AbortCdnRequest(c.Request) { api.AbortNotFound(c) return } c.Header(header.ContentSecurityPolicy, header.DefaultContentSecurityPolicy) c.Header(header.FrameOptions, header.DefaultFrameOptions) } }
Security is a middleware that adds security-related headers to the server's response.
var Static = func(conf *config.Config) gin.HandlerFunc { return func(c *gin.Context) { header.SetCacheControlImmutable(c, 0, true) if origin := conf.CORSOrigin(); origin != "" || header.AllowCORS(c.Request.URL.Path) && conf.UseCdn() { if origin == "" { c.Header(header.AccessControlAllowOrigin, header.Any) } else { c.Header(header.AccessControlAllowOrigin, origin) } if c.Request.Method == http.MethodOptions { c.Header(header.AccessControlAllowHeaders, conf.CORSHeaders()) c.Header(header.AccessControlAllowMethods, conf.CORSMethods()) c.Header(header.AccessControlMaxAge, header.DefaultAccessControlMaxAge) } } } }
Static is a middleware that adds static content-related headers to the server's response.
var WebDAVHandler = func(c *gin.Context, router *gin.RouterGroup, srv *webdav.Handler) {
srv.ServeHTTP(c.Writer, c.Request)
}
WebDAVHandler wraps the http request handler so that it can be customized.
Functions ¶
func Recovery ¶
func Recovery() gin.HandlerFunc
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
func StartAutoTLS ¶
StartAutoTLS starts the Web server with auto tls enabled.
func WebDAV ¶
func WebDAV(filePath string, router *gin.RouterGroup, conf *config.Config)
WebDAV handles requests to the "/originals" and "/import" endpoints.
func WebDAVAbortServerError ¶
WebDAVAbortServerError aborts the request with the status internal server error.
func WebDAVAbortUnauthorized ¶
WebDAVAbortUnauthorized aborts the request with the status unauthorized and requests authentication.
func WebDAVAuth ¶
func WebDAVAuth(conf *config.Config) gin.HandlerFunc
WebDAVAuth checks authentication and authentication before WebDAV requests are processed.
func WebDAVAuthSession ¶
func WebDAVAuthSession(c *gin.Context, authToken string) (sess *entity.Session, user *entity.User, sid string, cached bool)
WebDAVAuthSession returns the client session that belongs to the auth token provided, or returns nil if it was not found.
func WebDAVFileName ¶
func WebDAVFileName(request *http.Request, router *gin.RouterGroup, conf *config.Config) (fileName string)
WebDAVFileName determines the name and path of an uploaded file and returns its name if it exists.
func WebDAVSetFavoriteFlag ¶
func WebDAVSetFavoriteFlag(fileName string)
WebDAVSetFavoriteFlag adds the favorite flag to files uploaded via WebDAV.
func WebDAVSetFileMtime ¶
WebDAVSetFileMtime updaters the file modification time based on a Unix timestamp string.
Types ¶
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension represents a named package extension with callbacks.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package limiter provides an IP request rate limiter with Gin middleware.
|
Package limiter provides an IP request rate limiter with Gin middleware. |
Package wellknown provides data types and abstractions for service discovery endpoints.
|
Package wellknown provides data types and abstractions for service discovery endpoints. |