Documentation ¶
Overview ¶
Package httputil provides HTTP utility functions as well as its own http.Handler to complement the "net/http" and "net/http/httputil" packages found in the standard library.
Index ¶
Constants ¶
const CommonLogFmt = `%s - - [%s] "%s %s %s" %d %d "%s" "%s" %d`
Common Log Format See <http://httpd.apache.org/docs/1.3/logs.html#common>
Variables ¶
var (
LogFmt = CommonLogFmt // Log format to use
)
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, err string, code int)
Error wraps http.Error by writing appropriate error messages depending on the handler's Content-Type.
For example, with the Content-Type set to application/json and the error string "oops!", the response body would be `{"error":"oops!"}`
Types ¶
type Access ¶
type Access struct { RemoteAddr string Time time.Time Method string RequestURI string Proto string StatusCode int ContentLength int64 Referer string UserAgent string Duration time.Duration Request *http.Request }
Access represents a single HTTP access event (an answered request).
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements http.Handler.
func NewHandler ¶
NewHandler returns a new Handler which wraps the given http.Handler.
func (*Handler) Accept ¶
Accept instructs the handler to only fulfill requests which have an Accept header of the given MIME type. Otherwise, a 406 Not Acceptable is returned.
type ResponseWriter ¶
type ResponseWriter struct { StatusCode int ContentType string // contains filtered or unexported fields }
ResponseWriter wraps an http.ResponseWriter with additional capabilities.
func (*ResponseWriter) HasStatus ¶
func (rw *ResponseWriter) HasStatus() bool
HasStatus returns whether or not the ResponseWriter has a status.
func (*ResponseWriter) Header ¶
func (rw *ResponseWriter) Header() http.Header
Write wraps (*http.ResponseWriter).Header.
func (*ResponseWriter) Write ¶
func (rw *ResponseWriter) Write(b []byte) (int, error)
Write wraps (*http.ResponseWriter).Write.
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(status int)
WriteHeader wraps (*http.ResponseWriter).WriteHeader and records the given status.