Documentation ¶
Overview ¶
Package http provides a net/http.Handler implementation that wraps a imageserver.Server.
Index ¶
- func NewParamsHashETagFunc(newHashFunc func() hash.Hash) func(params imageserver.Params) string
- func ParseQueryBool(param string, req *http.Request, params imageserver.Params) error
- func ParseQueryFloat(param string, req *http.Request, params imageserver.Params) error
- func ParseQueryInt(param string, req *http.Request, params imageserver.Params) error
- func ParseQueryInt64(param string, req *http.Request, params imageserver.Params) error
- func ParseQueryString(param string, req *http.Request, params imageserver.Params)
- type CacheControlPublicHandler
- type Error
- type ExpiresHandler
- type Handler
- type ListParser
- type Parser
- type SourceParser
- type SourcePathParser
- type SourcePrefixParser
- type SourceTransformParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewParamsHashETagFunc ¶
func NewParamsHashETagFunc(newHashFunc func() hash.Hash) func(params imageserver.Params) string
NewParamsHashETagFunc returns a function that hashes the params and returns an ETag value.
It is intended to be used in Handler.ETagFunc.
func ParseQueryBool ¶
ParseQueryBool takes the param from the HTTP URL query, parse it as an bool and add it to the Params.
func ParseQueryFloat ¶
ParseQueryFloat takes the param from the HTTP URL query, parse it as a float64 and add it to the Params.
func ParseQueryInt ¶
ParseQueryInt takes the param from the HTTP URL query, parse it as an int and add it to the Params.
func ParseQueryInt64 ¶
ParseQueryInt64 takes the param from the HTTP URL query, parse it as an int64 and add it to the Params.
func ParseQueryString ¶
func ParseQueryString(param string, req *http.Request, params imageserver.Params)
ParseQueryString takes the param from the HTTP URL query and add it to the Params.
Types ¶
type CacheControlPublicHandler ¶
CacheControlPublicHandler is a net/http.Handler implementation that sets the "Cache-Control" header to "public".
It only sets the header if the status code is StatusOK/204 or StatusNotModified/304.
func (*CacheControlPublicHandler) ServeHTTP ¶
func (h *CacheControlPublicHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP implements net/http.Handler
type Error ¶
Error is a HTTP error.
It is supported by Handler.
func NewErrorDefaultText ¶
NewErrorDefaultText creates an Error with the default message associated with the code.
type ExpiresHandler ¶
ExpiresHandler is a net/http.Handler implementation that sets the "Expires" header.
It only sets the header if the status code is StatusOK/204 or StatusNotModified/304.
func (*ExpiresHandler) ServeHTTP ¶
func (eh *ExpiresHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP implements net/http.Handler.
type Handler ¶
type Handler struct { // Parser parses the HTTP request and fills the Params. Parser Parser // Server handles the image request. Server imageserver.Server // ETagFunc is an optional function that returns the ETag value for the given Params. // See https://en.wikipedia.org/wiki/HTTP_ETag . // The returned value must not be enclosed in quotes (they are added automatically). ETagFunc func(params imageserver.Params) string // ErrorFunc is an optional function that is called if there is an internal error. ErrorFunc func(err error, req *http.Request) }
Handler is a net/http.Handler implementation that wraps a imageserver.Server.
Supported methods are: GET and HEAD. Other method will return a StatusMethodNotAllowed/405 response.
It supports ETag/If-None-Match headers and returns a StatusNotModified/304 response accordingly. But it doesn't check if the Image really exists (the Server is not called).
Steps:
- Parse the HTTP request, and fill the Params.
- If the given If-None-Match header matches the ETag, return a StatusNotModified/304 response.
- Call the Server and get the Image.
- Return a StatusOK/200 response containing the Image.
Errors (returned by Parser or Server):
- *imageserver/http.Error will return a response with the given status code and message.
- *imageserver.ParamError will return a StatusBadRequest/400 response, with a message including the resolved HTTP param.
- *imageserver.ImageError will return a StatusBadRequest/400 response, with the given message.
- Other error will return a StatusInternalServerError/500 response, and ErrorFunc will be called.
Returned headers:
- Content-Type is set for StatusOK/200 response, and contains "image/{Image.Format}".
- Content-Length is set for StatusOK/200 response, and contains the Image size.
- ETag is set for StatusOK/200 and StatusNotModified/304 response, and contains the ETag value.
type ListParser ¶
type ListParser []Parser
ListParser is a Parser implementation that wraps a list of Parser.
func (ListParser) Parse ¶
func (lp ListParser) Parse(req *http.Request, params imageserver.Params) error
Parse implements Parser.
It iterates through all sub parsers. An error interrupts the iteration.
func (ListParser) Resolve ¶
func (lp ListParser) Resolve(param string) string
Resolve implements Parser.
It iterates through sub parsers, and return the first non-empty string.
type Parser ¶
type Parser interface { // Parse parses a *net/http.Request and fill Params. Parse(*http.Request, imageserver.Params) error // Resolve resolves an internal param to a HTTP param. // It returns the resolved HTTP param, or an empty string if it can not be resolved. // It is used by Handler to generate errors messages. Resolve(param string) (httpParam string) }
Parser represents a *net/http.Request parser.
type SourceParser ¶
type SourceParser struct{}
SourceParser is a Parser implementation that takes the "source" param from the HTTP URL query.
func (*SourceParser) Parse ¶
func (parser *SourceParser) Parse(req *http.Request, params imageserver.Params) error
Parse implements Parser.
func (*SourceParser) Resolve ¶
func (parser *SourceParser) Resolve(param string) string
Resolve implements Parser.
type SourcePathParser ¶
type SourcePathParser struct{}
SourcePathParser is a Parser implementation that takes the "source" param from the HTTP URL path.
func (*SourcePathParser) Parse ¶
func (parser *SourcePathParser) Parse(req *http.Request, params imageserver.Params) error
Parse implements Parser.
func (*SourcePathParser) Resolve ¶
func (parser *SourcePathParser) Resolve(param string) string
Resolve implements Parser.
type SourcePrefixParser ¶
SourcePrefixParser is a Parser implementation that adds a prefix to the "source" param.
func (*SourcePrefixParser) Parse ¶
func (ps *SourcePrefixParser) Parse(req *http.Request, params imageserver.Params) error
Parse implements Parser.
type SourceTransformParser ¶
SourceTransformParser is a Parser implementation that transforms the "source" param.
func (*SourceTransformParser) Parse ¶
func (ps *SourceTransformParser) Parse(req *http.Request, params imageserver.Params) error
Parse implements Parser.
Directories ¶
Path | Synopsis |
---|---|
Package crop provides a imageserver/http.Parser implementation for imageserver/image/crop.Processor.
|
Package crop provides a imageserver/http.Parser implementation for imageserver/image/crop.Processor. |
Package gamma provides a imageserver/http.Parser implementation for imageserver/image/gamma.CorrectionProcessor.
|
Package gamma provides a imageserver/http.Parser implementation for imageserver/image/gamma.CorrectionProcessor. |
Package gift provides imageserver/http.Parser implementations for imageserver/image/gift.
|
Package gift provides imageserver/http.Parser implementations for imageserver/image/gift. |
Package graphicsmagick provides a imageserver/http.Parser implementation for imageserver/graphicsmagick.Handler.
|
Package graphicsmagick provides a imageserver/http.Parser implementation for imageserver/graphicsmagick.Handler. |
Package image provides imageserver/http.Parser implementations for imageserver/image.
|
Package image provides imageserver/http.Parser implementations for imageserver/image. |
Package nfntresize provides a imageserver/http.Parser implementation for imageserver/image/nfntresize.Processor.
|
Package nfntresize provides a imageserver/http.Parser implementation for imageserver/image/nfntresize.Processor. |