http_

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const TusResumableDisabled = "1"
View Source
const UploadLengthDeferred = "1"

Variables

This section is empty.

Functions

func Client added in v1.0.16

func Client(u string) (*http.Client, error)

func ContentType added in v1.0.9

func ContentType(content io.Reader, name string) (ctype string, bufferedContent io.Reader, err error)

func Get added in v1.0.16

func Get(url string) (resp *http.Response, err error)

func GetProxySchemeAndHost

func GetProxySchemeAndHost(r *http.Request, allowForwarded bool) (scheme, host string)

GetProxySchemeAndHost extracts the host and used protocol (either HTTP or HTTPS) from the given request. If `allowForwarded` is set, the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers will also be checked to support proxies.

func Head(url string) (resp *http.Response, err error)

func Post added in v1.0.16

func Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

func PostForm added in v1.0.16

func PostForm(url string, data url.Values) (resp *http.Response, err error)

func ReplacePath added in v1.0.16

func ReplacePath(path string, h http.Handler) http.Handler

StripPrefix returns a handler that serves HTTP requests by removing the given prefix from the request URL's Path and invoking the handler h. StripPrefix handles a request for a path that doesn't begin with prefix by replying with an HTTP 404 not found error.

func ResolveProxyUrl

func ResolveProxyUrl(u *url.URL, r *http.Request, allowForwarded bool) *url.URL

func ServeContent added in v1.0.9

func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, content io.Reader, size int64)

ServeContent replies to the request using the content in the provided Reader. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.

If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.

If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.

If the content's Seek method work: ServeContent uses a seek to the end of the content to determine its size, and the param size is ignored. The same as http.ServeFile If the content's Seek method doesn't work: ServeContent uses the param size to generate a onlySizeSeekable as a pseudo io.ReadSeeker. If size < 0, use chunk or connection close instead

If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.

Note that *os.File implements the io.ReadSeeker interface.

Types

type ResumableUploadHandler

type ResumableUploadHandler struct {
	// contains filtered or unexported fields
}

ResumableUploadHandler is a ready to use handler with routing (using pat)

func NewResumableUploadHandler

func NewResumableUploadHandler(config tusd.Config) (*ResumableUploadHandler, error)

NewResumableUploadHandler creates a routed tus protocol handler. This is the simplest way to use tusd but may not be as configurable as you require. If you are integrating this into an existing app you may like to use tusd.NewUnroutedHandler instead. Using tusd.NewUnroutedHandler allows the tus handlers to be combined into your existing router (aka mux) directly. It also allows the GET and DELETE endpoints to be customized. These are not part of the protocol so can be changed depending on your needs.

func (*ResumableUploadHandler) DelFile

func (handler *ResumableUploadHandler) DelFile(w http.ResponseWriter, r *http.Request)

DelFile terminates an upload permanently.

func (*ResumableUploadHandler) GetFile

func (handler *ResumableUploadHandler) GetFile(w http.ResponseWriter, r *http.Request)

GetFile handles requests to download a file using a GET request. This is not part of the specification.

func (*ResumableUploadHandler) Handler

func (handler *ResumableUploadHandler) Handler(id string) http.Handler

func (*ResumableUploadHandler) HeadFile

func (handler *ResumableUploadHandler) HeadFile(w http.ResponseWriter, r *http.Request)

HeadFile returns the length and offset for the HEAD request

func (*ResumableUploadHandler) Middleware

func (handler *ResumableUploadHandler) Middleware(h http.Handler) http.Handler

Middleware checks various aspects of the request and ensures that it conforms with the spec. Also handles method overriding for clients which cannot make PATCH AND DELETE requests. If you are using the tusd handlers directly you will need to wrap at least the POST and PATCH endpoints in this middleware.

func (*ResumableUploadHandler) PatchFile

func (handler *ResumableUploadHandler) PatchFile(w http.ResponseWriter, r *http.Request)

PatchFile adds a chunk to an upload. This operation is only allowed if enough space in the upload is left.

func (*ResumableUploadHandler) PostFile

func (handler *ResumableUploadHandler) PostFile(w http.ResponseWriter, r *http.Request)

PostFile creates a new file upload using the datastore after validating the length and parsing the metadata.

func (*ResumableUploadHandler) PutFile

func (handler *ResumableUploadHandler) PutFile(w http.ResponseWriter, r *http.Request)

PutFile upgrades a new file upload using the datastore after validating the length and parsing the metadata.

type UploadHandler

type UploadHandler struct {
	http.Handler

	MaxSize int64
	// BasePath defines the URL path used for handling uploads, e.g. "/files/".
	// If no trailing slash is presented it will be added. You may specify an
	// absolute URL containing a scheme, e.g. "http://tus.io"
	BasePath *url.URL

	*log.FieldLogger

	// CompleteUploads is used to send notifications whenever an upload is
	// completed by a user. The FileInfo will contain information about this
	// upload after it is completed. Sending to this channel will only
	// happen if the NotifyCompleteUploads field is set to true in the Config
	// structure. Notifications will also be sent for completions using the
	// Concatenation extension.
	NotifyCompleteUploads bool
	CompleteUploads       chan tusd.FileInfo
	// TerminatedUploads is used to send notifications whenever an upload is
	// terminated by a user. The FileInfo will contain information about this
	// upload gathered before the termination. Sending to this channel will only
	// happen if the NotifyTerminatedUploads field is set to true in the Config
	// structure.
	NotifyTerminatedUploads bool
	TerminatedUploads       chan tusd.FileInfo
	// UploadProgress is used to send notifications about the progress of the
	// currently running uploads. For each open PATCH request, every second
	// a FileInfo instance will be send over this channel with the Offset field
	// being set to the number of bytes which have been transfered to the server.
	// Please be aware that this number may be higher than the number of bytes
	// which have been stored by the data store! Sending to this channel will only
	// happen if the NotifyUploadProgress field is set to true in the Config
	// structure.
	NotifyUploadProgress bool
	UploadProgress       chan tusd.FileInfo
	// CreatedUploads is used to send notifications about the uploads having been
	// created. It triggers post creation and therefore has all the FileInfo incl.
	// the ID available already. It facilitates the post-create hook. Sending to
	// this channel will only happen if the NotifyCreatedUploads field is set to
	// true in the Config structure.
	NotifyCreatedUploads bool
	CreatedUploads       chan tusd.FileInfo
	// contains filtered or unexported fields
}

UploadHandler exposes methods to handle requests as part of the tus protocol, such as PostFile, HeadFile, PatchFile and DelFile. In addition the GetFile method is provided which is, however, not part of the specification.

func NewUploadHandler

func NewUploadHandler(config tusd.Config) (*UploadHandler, error)

NewUploadHandler creates a new handler without routing using the given configuration. It exposes the http handlers which need to be combined with a router (aka mux) of your choice. If you are looking for preconfigured handler see NewHandler.

func (*UploadHandler) DelFile

func (handler *UploadHandler) DelFile(w http.ResponseWriter, r *http.Request)

DelFile terminates an upload permanently.

func (*UploadHandler) GetFile

func (handler *UploadHandler) GetFile(w http.ResponseWriter, r *http.Request)

GetFile handles requests to download a file using a GET request. This is not part of the specification.

func (*UploadHandler) HeadFile

func (handler *UploadHandler) HeadFile(w http.ResponseWriter, r *http.Request)

HeadFile returns the length and offset for the HEAD request

func (*UploadHandler) Middleware

func (handler *UploadHandler) Middleware(h http.Handler) http.Handler

Middleware checks various aspects of the request and ensures that it conforms with the spec. Also handles method overriding for clients which cannot make PATCH AND DELETE requests. If you are using the tusd handlers directly you will need to wrap at least the POST and PATCH endpoints in this middleware.

func (*UploadHandler) PatchFile

func (handler *UploadHandler) PatchFile(w http.ResponseWriter, r *http.Request)

PatchFile adds a chunk to an upload. This operation is only allowed if enough space in the upload is left.

func (*UploadHandler) PostFile

func (handler *UploadHandler) PostFile(w http.ResponseWriter, r *http.Request)

PostFile creates a new file upload using the datastore after validating the length and parsing the metadata.

func (*UploadHandler) PutFile

func (handler *UploadHandler) PutFile(w http.ResponseWriter, r *http.Request)

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html 9.6 PUT PutFile upgrades a new file upload using the datastore after validating the length and parsing the metadata. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem.

Jump to

Keyboard shortcuts

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