httpxtra

package
v1.0.1-0...-5b593f1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2015 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

httpxtra is a wrapper for http.Handler that adds extra features to the server:

  • Custom logging
  • Support for listening on TCP or UNIX sockets
  • Support X-Real-IP and X-Forwarded-For as the remote IP if the server sits behind a proxy or load balancer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApacheCommonLog

func ApacheCommonLog(r *http.Request, created time.Time, status, bytes int) string

ApacheCommonLog returns an Apache Common access log string.

func ListenAndServe

func ListenAndServe(srv http.Server) error

ListenAndServe can listen on both TCP and UNIX sockets.

Types

type Handler

type Handler struct {
	Handler  http.Handler
	Logger   LoggerFunc
	XHeaders bool
}

Handler is the http.Handler wrapper with extra features.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is a wrapper for the request, which can modify the value of the RemoteAddr and later calls the logger function.

Note that when XHeaders are enabled, the value of RemoteAddr might be a copy of the X-Real-IP or X-Forwarded-For HTTP header, which can be a comma separated list of IPs.

See http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers for details.

type LogWriter

type LogWriter struct {
	ResponseWriter http.ResponseWriter
	Bytes          int
	Status         int
}

func (*LogWriter) CloseNotify

func (lw *LogWriter) CloseNotify() <-chan bool

func (*LogWriter) Flush

func (lw *LogWriter) Flush()

func (*LogWriter) Header

func (lw *LogWriter) Header() http.Header

func (*LogWriter) Hijack

func (lw *LogWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*LogWriter) Write

func (lw *LogWriter) Write(b []byte) (int, error)

func (*LogWriter) WriteHeader

func (lw *LogWriter) WriteHeader(s int)

type LoggerFunc

type LoggerFunc func(r *http.Request, created time.Time, status, bytes int)

LoggerFunc are functions called by httpxtra.Handler at the end of each request.

Jump to

Keyboard shortcuts

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