server

package
v0.0.0-...-f83a9f7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 36 Imported by: 0

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

View Source
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"
)
View Source
const (
	WebDAVOriginals = "/originals"
	WebDAVImport    = "/import"
)

Variables

View Source
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.

View Source
var BasicAuthRealm = "Basic realm=\"WebDAV Authorization Required\""

Security is a middleware that adds security-related headers to the server's response.

View Source
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.

View Source
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 AutoTLS

func AutoTLS(conf *config.Config) (*autocert.Manager, error)

AutoTLS enables automatic HTTPS via Let's Encrypt.

func Logger

func Logger() gin.HandlerFunc

Logger instances a Logger middleware for Gin.

func Recovery

func Recovery() gin.HandlerFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

func Register

func Register(name string, init func(router *gin.Engine, conf *config.Config) error)

Register registers a new package extension.

func Start

func Start(ctx context.Context, conf *config.Config)

Start the REST API server using the configuration provided

func StartAutoTLS

func StartAutoTLS(s *http.Server, m *autocert.Manager, conf *config.Config)

StartAutoTLS starts the Web server with auto tls enabled.

func StartHttp

func StartHttp(s *http.Server, l net.Listener)

StartHttp starts the Web server in http mode.

func StartTLS

func StartTLS(s *http.Server, httpsCert, privateKey string)

StartTLS starts the Web server in https mode.

func WebDAV

func WebDAV(filePath string, router *gin.RouterGroup, conf *config.Config)

WebDAV handles requests to the "/originals" and "/import" endpoints.

func WebDAVAbortServerError

func WebDAVAbortServerError(c *gin.Context)

WebDAVAbortServerError aborts the request with the status internal server error.

func WebDAVAbortUnauthorized

func WebDAVAbortUnauthorized(c *gin.Context)

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

func WebDAVSetFileMtime(fileName string, mtimeUnix int64)

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.

type Extensions

type Extensions []Extension

Extensions represents a list of package extensions.

func Ext

func Ext() (ext Extensions)

Ext returns all registered package extensions.

func (Extensions) Init

func (ext Extensions) Init(router *gin.Engine, conf *config.Config)

Init initializes the registered extensions.

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.

Jump to

Keyboard shortcuts

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