Documentation ¶
Overview ¶
Package httph provides some helper for system http package.
Index ¶
Constants ¶
const ( ScanErrorTypeNoSuchField ScanErrorType = iota // There is not field in form with requested name ScanErrorTypeMultipleValues = iota // There is more than 1 field in form with requested name ScanErrorTypeIncompatibleValue = iota // Value in form is incompatible with requested field type (i.e. trying to save "one" as int) ScanErrorTypeIncompatibleType = iota // Function unable to handle field with such type (i.e. truing to scan custom type) )
Define available ScanError types
const CookieDeleteUnixTime = 1
CookieDeleteUnixTime is UNIX time near beginning of UNIX epoch. It is used as cookie expiration time to remove cookie.
Variables ¶
This section is empty.
Functions ¶
func AuthError ¶
func AuthError(w http.ResponseWriter, r *http.Request)
AuthError replies to the request with an HTTP 401 not authorized error. r *http.Request does not used and may be nil.
func CookieDeleteTime ¶
CookieDeleteTime returns Time near beginning of UNIX epoch. This time should be used as cookie expiration time to remove cookie.
func ScanFormData ¶
ScanFormData scans Request.Form for required fields and save its value. Required fields names and variables to store values described by fields. This function accept for each required field exactly one value in form. There is error if zero or more than one fields with requested name exists in form. This function supports only following types of fields: [u]int[8/16/32/64], bools & strings. *int* will be parsed using strconvh.ParseInt* with base of 10. For bools valid values are only "on" & "off" (case sensitive). Strings accepted as-is. Returned error is always of type ScanError or nil. Warning: r.ParseForm should be performed before calling this function.
Types ¶
type ScanError ¶
type ScanError struct { FieldNum int // problem field number (beginning from 0) FieldName string // problem field name Type ScanErrorType // type of error SubError error // child error, used to exactly describe problem with incompatible value (nil for other types of error) }
ScanError define error occurred while scanning form
type ScanErrorType ¶
type ScanErrorType uint8
ScanErrorType define the type of error occurred while scanning form
type ScanField ¶
type ScanField struct { Name string // field name Value interface{} // variable to store value }
ScanField stores requested field name and variable to save value for ScanFormData.
type StaticDataElement ¶
type StaticDataElement struct { UnixTime int64 // Store original file modification time as UNIX time (warning: http.TimeFormat doesn't use anything less then second in "If-Modified-Since" HTTP requests) Mime string // Store mime type Data []byte // Binary data (file content) }
StaticDataElement used to store arbitrary file in HTTP server application.
func (*StaticDataElement) ServeHTTP ¶
func (s *StaticDataElement) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implement http.Handler interface for *StaticDataElement. ServeHTTP implement GET & HEAD HTTP methods. On POST method it answers with 405 - MethodNotAllowed. On other methods it answers with 501 - NotImplemented. ServeHTTP set "Last-Modified" header on GET & HEAD methods and use "If-Modified-Since" header on GET method to send payload only if needed. Happened errors just ignored. So usually it is enough to just register StaticDataElement using http.ServeMux.Handle.
func (*StaticDataElement) Time ¶
func (s *StaticDataElement) Time() time.Time
Time return original file modification time as time.Time