web

package
v6.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 11 Imported by: 45

Documentation

Index

Constants

View Source
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 CopyHeader

func CopyHeader(source http.Header) http.Header

func CopyHeaderTo

func CopyHeaderTo(source http.Header, dest *http.Header)

func GetClientIPPort

func GetClientIPPort(r *http.Request) (string, string)

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 GetIP

func GetIP(r *http.Request) (net.IP, error)

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

func (*ConnMap) Add

func (cm *ConnMap) Add(conn net.Conn)

func (*ConnMap) Get

func (cm *ConnMap) Get(remoteAddr string) (net.Conn, bool)

func (*ConnMap) Len

func (cm *ConnMap) Len() int

func (*ConnMap) Remove

func (cm *ConnMap) Remove(remoteAddr string)

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) Write

func (t *HTTPResponseWriterTee) Write(b []byte) (int, error)

func (*HTTPResponseWriterTee) WriteHeader

func (t *HTTPResponseWriterTee) WriteHeader(code int)

type Hdr

type Hdr struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

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) Read

func (c *InterceptConn) Read(b []byte) (n int, err error)

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

func (*InterceptConn) Write

func (c *InterceptConn) Write(b []byte) (n int, err error)

type InterceptListener

type InterceptListener struct {
	// contains filtered or unexported fields
}

func (*InterceptListener) Accept

func (l *InterceptListener) Accept() (net.Conn, error)

func (*InterceptListener) Addr

func (l *InterceptListener) Addr() net.Addr

func (*InterceptListener) Close

func (l *InterceptListener) Close() error

type ModHdrs

type ModHdrs struct {
	Set  []Hdr    `json:"set"`
	Drop []string `json:"drop"`
}

func (*ModHdrs) Any

func (mh *ModHdrs) Any() bool

Any returns whether any header modifications exist

func (*ModHdrs) Mod

func (mh *ModHdrs) Mod(h http.Header)

Mod drops and sets the headers in h according to its rules.

Jump to

Keyboard shortcuts

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