icap

package module
v0.0.0-...-bdcc1ba Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2013 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package icap provides an extensible ICAP server.

Index

Constants

This section is empty.

Variables

View Source
var DefaultServeMux = NewServeMux()

DefaultServeMux is the default ServeMux used by Serve.

Functions

func Handle

func Handle(pattern string, handler Handler)

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

func ListenAndServe(addr string, handler Handler) error

ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func NewBridgedResponseWriter

func NewBridgedResponseWriter(w ResponseWriter) http.ResponseWriter

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, url_ 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

func Serve(l net.Listener, handler Handler) error

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)

Pass use the local HTTP server to generate a response for an ICAP request.

func StatusText

func StatusText(code int) string

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

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

func RedirectHandler(url_ string, code int) Handler

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)

	// 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)
}

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 NewServeMux

func NewServeMux() *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler Handler)

Handle registers the handler for the given pattern.

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
}

A Server defines parameters for running an ICAP server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

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

func (srv *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service thread for each. The service threads read requests and then call srv.Handler to reply to them.

Directories

Path Synopsis
An example of how to use go-icap.
An example of how to use go-icap.

Jump to

Keyboard shortcuts

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