Documentation
¶
Overview ¶
Package icap provides an extensible ICAP server.
Index ¶
- Variables
- func Handle(pattern string, handler Handler)
- func HandleFunc(pattern string, handler func(ResponseWriter, *Request))
- func ListenAndServe(addr string, handler Handler) error
- func ListenAndServeTLS(addr, cert, key string, handler Handler) error
- func NewBridgedResponseWriter(w ResponseWriter) http.ResponseWriter
- func NewChunkedWriter(w io.Writer) io.WriteCloser
- func NotFound(w ResponseWriter, r *Request)
- func Redirect(w ResponseWriter, r *Request, redirectURL string, code int)
- func Serve(l net.Listener, handler Handler) error
- func ServeLocally(w ResponseWriter, req *Request)
- func ServeLocallyFromHandler(w ResponseWriter, req *Request, mux http.Handler)
- func StatusText(code int) string
- type Handler
- type HandlerFunc
- type Request
- type ResponseWriter
- type ServeMux
- type Server
Constants ¶
This section is empty.
Variables ¶
var DefaultServeMux = NewServeMux()
DefaultServeMux is the default ServeMux used by Serve.
Functions ¶
func Handle ¶
Handle registers the handler for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.
func HandleFunc ¶
func HandleFunc(pattern string, handler func(ResponseWriter, *Request))
HandleFunc registers the handler function for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.
func ListenAndServeTLS ¶
ListenAndServeTLS --
func NewBridgedResponseWriter ¶
func NewBridgedResponseWriter(w ResponseWriter) http.ResponseWriter
NewBridgedResponseWriter Create an http.ResponseWriter that encapsulates its response in an ICAP response.
func NewChunkedWriter ¶
func NewChunkedWriter(w io.Writer) io.WriteCloser
NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP "chunked" format before writing them to w. Closing the returned chunkedWriter sends the final 0-length chunk that marks the end of the stream.
NewChunkedWriter is not needed by normal applications. The http package adds chunking automatically if handlers don't set a Content-Length header. Using NewChunkedWriter inside a handler would result in double chunking or chunking with a Content-Length length, both of which are wrong.
func NotFound ¶
func NotFound(w ResponseWriter, r *Request)
NotFound replies to the request with an HTTP 404 not found error.
func Redirect ¶
func Redirect(w ResponseWriter, r *Request, redirectURL string, code int)
Redirect replies to the request with a redirect to url, which may be a path relative to the request path.
func Serve ¶
Serve accepts incoming ICAP connections on the listener l, creating a new service thread for each. The service threads read requests and then call handler to reply to them.
func ServeLocally ¶
func ServeLocally(w ResponseWriter, req *Request)
ServeLocally Pass use the local HTTP server to generate a response for an ICAP request.
func ServeLocallyFromHandler ¶
func ServeLocallyFromHandler(w ResponseWriter, req *Request, mux http.Handler)
ServeLocallyFromHandler ---
func StatusText ¶
StatusText returns a text for the ICAP status code. It returns the empty string if the code is unknown.
Types ¶
type Handler ¶
type Handler interface {
ServeICAP(ResponseWriter, *Request)
}
Handler Objects implementing the Handler interface can be registered to serve ICAP requests.
ServeICAP should write reply headers and data to the ResponseWriter and then return.
func NotFoundHandler ¶
func NotFoundHandler() Handler
NotFoundHandler returns a simple request handler that replies to each request with a “404 page not found” reply.
func RedirectHandler ¶
RedirectHandler returns a request handler that redirects each request it receives to the given url using the given status code.
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
The HandlerFunc type is an adapter to allow the use of ordinary functions as ICAP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) ServeICAP ¶
func (f HandlerFunc) ServeICAP(w ResponseWriter, r *Request)
ServeICAP calls f(w, r).
type Request ¶
type Request struct {
Method string // REQMOD, RESPMOD, OPTIONS, etc.
RawURL string // The URL given in the request.
URL *url.URL // Parsed URL.
Proto string // The protocol version.
Header textproto.MIMEHeader // The ICAP header
RemoteAddr string // the address of the computer sending the request
Preview []byte // the body data for an ICAP preview
// The HTTP messages.
Request *http.Request
Response *http.Response
}
A Request represents a parsed ICAP request.
func ReadRequest ¶
func ReadRequest(b *bufio.ReadWriter) (req *Request, err error)
ReadRequest reads and parses a request from b.
type ResponseWriter ¶
type ResponseWriter interface {
// Header returns the header map that will be sent by WriteHeader.
// Changing the header after a call to WriteHeader (or Write) has
// no effect.
Header() http.Header
// Write writes the data to the connection as part of an ICAP reply.
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK, nil)
// before writing the data.
Write([]byte) (int, error)
// Write raw data to the connection.
WriteRaw(string)
// WriteHeader sends an ICAP response header with status code.
// Then it sends an HTTP header if httpMessage is not nil.
// httpMessage may be an *http.Request or an *http.Response.
// hasBody should be true if there will be calls to Write(), generating a message body.
WriteHeader(code int, httpMessage interface{}, hasBody bool)
}
ResponseWriter ---
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is an ICAP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL.
For more details, see the documentation for http.ServeMux
func (*ServeMux) HandleFunc ¶
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request))
HandleFunc registers the handler function for the given pattern.
func (*ServeMux) ServeICAP ¶
func (mux *ServeMux) ServeICAP(w ResponseWriter, r *Request)
ServeICAP dispatches the request to the handler whose pattern most closely matches the request URL.
type Server ¶
type Server struct {
Addr string // TCP address to listen on, ":1344" if empty
Handler Handler // handler to invoke
ReadTimeout time.Duration
WriteTimeout time.Duration
DebugLevel int
}
A Server defines parameters for running an ICAP server.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":1344" is used.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS ---