Documentation ¶
Overview ¶
Package upload contains a HTTP handler that provides facilities for uploading files.
Use flags for http server implementations other than Go's own, like this:
go build -tags "caddyserver0.9 caddyserver1.0" …
Those tags start with the first version, followed by all major.minor up to its current version. Please see how Go does it: https://golang.org/pkg/go/build/#hdr-Build_Constraints
Absent any meaningful flags use the http.Handler implementation (see the following example).
Example ¶
var ( scope = "/" // prefix to http.Request.URL.Path directory = "/var/tmp" next = http.FileServer(http.Dir(directory)) ) cfg := NewDefaultConfiguration(directory) uploadHandler, _ := NewHandler(scope, cfg, next) http.Handle(scope, uploadHandler) // http.ListenAndServe(":9000", nil)
Output:
Index ¶
Examples ¶
Constants ¶
const ( // AlwaysRejectRunes contains runes that are not safe to use with network shares. // // Please note that '/' is already discarded at an earlier stage. AlwaysRejectRunes = `"*:<>?|\` )
Variables ¶
This section is empty.
Functions ¶
func FinishSetup ¶
func FinishSetup() error
FinishSetup communicates any collected white- and blacklists to the operating system.
Call this on systems and with seervers that support OS-based locking down. Servers that feature a dynamic reconfiguration or the like should not call this. Do not call this in unit tests.
Subject to change, has only an effect on OpenBSD.
func IsAcceptableFilename ¶
func IsAcceptableFilename(s string, reduceAcceptableRunesTo []*unicode.RangeTable, enforceForm *norm.Form) bool
IsAcceptableFilename is used to enforce filenames in wanted alphabet(s). Setting 'reduceAcceptableRunesTo' reduces the supremum unicode.PrintRanges.
A string with runes – other than U+0020 (space) or U+2009 (spatium) – representing space will be rejected.
Filenames are not transliterated to prevent loops within clusters of mirrors.
func ParseUnicodeBlockList ¶
func ParseUnicodeBlockList(str string) (*unicode.RangeTable, error)
ParseUnicodeBlockList naïvely translates a string with space-delimited Unicode ranges to Go's unicode.RangeTable.
All elements must fit into uint32. A Range must begin with its lower bound, and ranges must not overlap (we don't check this here!).
The format of one range is as follows, with 'stride' being set to '1' if left empty.
<low>-<high>[:<stride>]
Types ¶
type Handler ¶
type Handler struct { Next http.Handler Config *ScopeConfiguration Scope string // Basically this will be stripped from the full URL and the target path swapped in. }
Handler implements http.Handler.
func NewHandler ¶
NewHandler creates a new instance of this plugin's upload handler, meant to be used in Go's own http server.
XXX: Its responsibility is to reject invalid or formally incorrect configurations.
'next' is optional. 'scope' is a string and the prefix of the upload destination's URL.Path, like `/dir/to/upload/destination`.
type ScopeConfiguration ¶
type ScopeConfiguration struct { // How big a difference between 'now' and the provided timestamp do we tolerate? // In seconds. Due to possible optimizations this should be an order of 2. // A reasonable default is 1<<2. TimestampTolerance uint64 MaxFilesize uint64 MaxTransactionSize uint64 // Target directory on disk that serves as upload destination. WriteToPath string // Uploaded files can be gotten back from here. // If ≠ "" this will trigger sending headers such as "Location". ApparentLocation string // Maps KeyIDs to shared secrets. // Here the latter are already decoded from base64 to binary. // Request verification is disabled if this is empty. IncomingHmacSecrets auth.HmacSecrets IncomingHmacSecretsLock sync.RWMutex // If false, this plugin returns HTTP Errors. // If true, passes the given request to the next middleware // which could respond with an Error of its own, poorly obscuring where this plugin is used. SilenceAuthErrors bool // Enables MOVE, DELETE, and similar. Without this only POST and PUT will be recognized. EnableWebdav bool // Set this to reject any non-conforming filenames. UnicodeForm *struct{ Use norm.Form } // Limit the acceptable alphabet(s) for filenames by setting this value. RestrictFilenamesTo []*unicode.RangeTable // Append '_' and a randomized suffix of that length. RandomizedSuffixLength uint32 }
ScopeConfiguration represents the settings of a scope (URL path).
func NewDefaultConfiguration ¶
func NewDefaultConfiguration(targetDirectory string) *ScopeConfiguration
NewDefaultConfiguration creates a new default configuration.
Directories ¶
Path | Synopsis |
---|---|
Package auth implements authorization scheme Signature, which works using MIME headers.
|
Package auth implements authorization scheme Signature, which works using MIME headers. |