Documentation ¶
Index ¶
- Constants
- func CopyHeader(source http.Header) http.Header
- func CopyHeaderTo(source http.Header, dest *http.Header)
- func GetClientIPPort(r *http.Request) (string, string)
- func GetIP(r *http.Request) (net.IP, error)
- func Request(transport *http.Transport, r *http.Request) (int, http.Header, []byte, time.Time, time.Time, error)
- func Respond(w http.ResponseWriter, code int, header http.Header, body []byte, ...) (uint64, error)
- func ServeErr(w http.ResponseWriter, code int) (uint64, error)
- func ServeReqErr(w http.ResponseWriter) (int, uint64, error)
- func TryFlush(w http.ResponseWriter)
- func TryGetBytesWritten(w http.ResponseWriter, conn *InterceptConn, bytesWritten uint64) uint64
- type ConnMap
- func InterceptListen(network, laddr string) (net.Listener, *ConnMap, func(net.Conn, http.ConnState), error)
- func InterceptListenTLS(network string, laddr string, certs []tls.Certificate, h2Disabled bool) (net.Listener, *ConnMap, func(net.Conn, http.ConnState), *tls.Config, error)
- func NewConnMap() *ConnMap
- type HTTPResponseWriterTee
- type Hdr
- type InterceptConn
- func (c *InterceptConn) BytesRead() int
- func (c *InterceptConn) BytesWritten() int
- func (c *InterceptConn) Close() error
- func (c *InterceptConn) LocalAddr() net.Addr
- func (c *InterceptConn) Read(b []byte) (n int, err error)
- func (c *InterceptConn) Real() net.Conn
- func (c *InterceptConn) RemoteAddr() net.Addr
- func (c *InterceptConn) SetDSCP(dscp int) error
- func (c *InterceptConn) SetDeadline(t time.Time) error
- func (c *InterceptConn) SetReadDeadline(t time.Time) error
- func (c *InterceptConn) SetWriteDeadline(t time.Time) error
- func (c *InterceptConn) Write(b []byte) (n int, err error)
- type InterceptListener
- type ModHdrs
Constants ¶
const RemapTextKey = "remap_text"
RemapTextKey is the plugin shared data key inserted by grovetccfg for the Remap Line of the Delivery Service in Traffic Control, Traffic Ops.
Variables ¶
This section is empty.
Functions ¶
func GetClientIPPort ¶
GetClientIPPort returns the client IP address of the given request, and the port. It returns the first x-forwarded-for IP if any, else the RemoteAddr.
func Request ¶
func Request(transport *http.Transport, r *http.Request) (int, http.Header, []byte, time.Time, time.Time, error)
request makes the given request and returns its response code, headers, body, the request time, response time, and any error.
func Respond ¶
func Respond(w http.ResponseWriter, code int, header http.Header, body []byte, connectionClose bool) (uint64, error)
Respond writes the given code, header, and body to the ResponseWriter. If connectionClose, a Connection: Close header is also written. Returns the bytes written, and any error.
func ServeErr ¶
func ServeErr(w http.ResponseWriter, code int) (uint64, error)
ServeErr writes the given error code to w, writes the text for that code to the body, and returns the code sent, bytes written, and any write error.
func ServeReqErr ¶
func ServeReqErr(w http.ResponseWriter) (int, uint64, error)
ServeReqErr writes the appropriate response to the client, via given writer, for a generic request error. Returns the code sent, the body bytes written, and any write error.
func TryFlush ¶
func TryFlush(w http.ResponseWriter)
TryFlush calls Flush on w if it's an http.Flusher. If it isn't, it returns without error.
func TryGetBytesWritten ¶
func TryGetBytesWritten(w http.ResponseWriter, conn *InterceptConn, bytesWritten uint64) uint64
TryGetBytesWritten attempts to get the real bytes written to the given conn. It takes the bytesWritten as returned by Write(). It forcibly calls Flush() in order to force a write to the conn. Then, it attempts to get the more accurate bytes written to the Conn. If this fails, the given and less accurate bytesWritten is returned. If everything succeeds, the accurate bytes written to the Conn is returned.
Types ¶
type ConnMap ¶
type ConnMap struct {
// contains filtered or unexported fields
}
func InterceptListen ¶
func InterceptListen(network, laddr string) (net.Listener, *ConnMap, func(net.Conn, http.ConnState), error)
InterceptListen creates and returns a net.Listener via net.Listen, which is wrapped with an intercepter, which counts Conn read and write bytes. If you want a `grove.NewCacheHandler` to be able to count in and out bytes per remap rule in the stats interface, it must be served with a listener created via InterceptListen or InterceptListenTLS.
func InterceptListenTLS ¶
func InterceptListenTLS(network string, laddr string, certs []tls.Certificate, h2Disabled bool) (net.Listener, *ConnMap, func(net.Conn, http.ConnState), *tls.Config, error)
InterceptListenTLS is like InterceptListen but for serving HTTPS. It returns the tls.Config, which must be set on the http.Server using this listener for HTTP/2 to be set up.
func NewConnMap ¶
func NewConnMap() *ConnMap
type HTTPResponseWriterTee ¶
type HTTPResponseWriterTee struct { // headers http.Header Bytes []byte Code int WrittenHeader http.Header // contains filtered or unexported fields }
HTTPResponseWriterTee fulfills `http.ResponseWriter`
func NewHTTPResponseWriterTee ¶
func NewHTTPResponseWriterTee(w http.ResponseWriter) *HTTPResponseWriterTee
func (*HTTPResponseWriterTee) Header ¶
func (t *HTTPResponseWriterTee) Header() http.Header
func (*HTTPResponseWriterTee) WriteHeader ¶
func (t *HTTPResponseWriterTee) WriteHeader(code int)
type InterceptConn ¶
type InterceptConn struct {
// contains filtered or unexported fields
}
func (*InterceptConn) BytesRead ¶
func (c *InterceptConn) BytesRead() int
func (*InterceptConn) BytesWritten ¶
func (c *InterceptConn) BytesWritten() int
func (*InterceptConn) Close ¶
func (c *InterceptConn) Close() error
func (*InterceptConn) LocalAddr ¶
func (c *InterceptConn) LocalAddr() net.Addr
func (*InterceptConn) Real ¶
func (c *InterceptConn) Real() net.Conn
func (*InterceptConn) RemoteAddr ¶
func (c *InterceptConn) RemoteAddr() net.Addr
func (*InterceptConn) SetDSCP ¶
func (c *InterceptConn) SetDSCP(dscp int) error
SetDSCP attempts to set the DSCP flag on the TCP connection of the InterceptConn (TOS in IPv4, Traffic Class in IPv6). Returns any error. Note this is not guaranteed to succeed on all operating systems. In particular, these functions are known to fail on OS X, and may or may not succeed on various Linux kernels and distributions. Callers should expect failure, and it is recommended the connection and request continue to be handled.
func (*InterceptConn) SetDeadline ¶
func (c *InterceptConn) SetDeadline(t time.Time) error
func (*InterceptConn) SetReadDeadline ¶
func (c *InterceptConn) SetReadDeadline(t time.Time) error
func (*InterceptConn) SetWriteDeadline ¶
func (c *InterceptConn) SetWriteDeadline(t time.Time) error
type InterceptListener ¶
type InterceptListener struct {
// contains filtered or unexported fields
}
func (*InterceptListener) Addr ¶
func (l *InterceptListener) Addr() net.Addr
func (*InterceptListener) Close ¶
func (l *InterceptListener) Close() error