Documentation ¶
Overview ¶
Package icapclient is a client package for the ICAP protocol
Here is a basic example:
package main import ( "fmt" "log" "net/http" "time" ic "github.com/egirna/icap-client" ) func main() { /* preparing the http request required for the RESPMOD */ httpReq, err := http.NewRequest(http.MethodGet, "http://localhost:8000/sample.pdf", nil) if err != nil { log.Fatal(err) } /* making the http client & making the request call to get the response needed for the icap RESPMOD call */ httpClient := &http.Client{} httpResp, err := httpClient.Do(httpReq) if err != nil { log.Fatal(err) } /* making a icap request with OPTIONS method */ optReq, err := ic.NewRequest(ic.MethodOPTIONS, "icap://127.0.0.1:1344/respmod", nil, nil) if err != nil { log.Fatal(err) return } /* making the icap client responsible for making the requests */ client := &ic.Client{ Timeout: 5 * time.Second, } /* making the OPTIONS request call */ optResp, err := client.Do(optReq) if err != nil { log.Fatal(err) return } /* making a icap request with RESPMOD method */ req, err := ic.NewRequest(ic.MethodRESPMOD, "icap://127.0.0.1:1344/respmod", httpReq, httpResp) if err != nil { log.Fatal(err) } req.SetPreview(optResp.PreviewBytes) // setting the preview bytes obtained from the OPTIONS call /* making the RESPMOD request call */ resp, err := client.Do(req) if err != nil { log.Fatal(err) } fmt.Println(resp.StatusCode) }
Index ¶
Constants ¶
const ( MethodOPTIONS = "OPTIONS" MethodRESPMOD = "RESPMOD" MethodREQMOD = "REQMOD" )
the icap request methods
const ( ErrInvalidScheme = "the url scheme must be icap://" ErrMethodNotRegistered = "the requested method is not registered" ErrInvalidHost = "the requested host is invalid" ErrConnectionNotOpen = "no open connection to close" ErrInvalidTCPMsg = "invalid tcp message" ErrREQMODWithNoReq = "http request cannot be nil for method REQMOD" ErrREQMODWithResp = "http response must be nil for method REQMOD" ErrRESPMODWithNoResp = "http response cannot be nil for method RESPMOD" )
the error messages
const ( SchemeICAP = "icap" ICAPVersion = "ICAP/1.0" HTTPVersion = "HTTP/1.1" SchemeHTTPReq = "http_request" SchemeHTTPResp = "http_response" CRLF = "\r\n" DoubleCRLF = "\r\n\r\n" LF = "\n" )
general constants required for the package
const ( PreviewHeader = "Preview" MethodsHeader = "Methods" AllowHeader = "Allow" EncapsulatedHeader = "Encapsulated" TransferPreviewHeader = "Transfer-Preview" ServiceHeader = "Service" ISTagHeader = "ISTag" OptBodyTypeHeader = "Opt-body-type" MaxConnectionsHeader = "Max-Connections" OptionsTTLHeader = "Options-TTL" ServiceIDHeader = "Service-ID" TransferIgnoreHeader = "Transfer-Ignore" TransferCompleteHeader = "Transfer-Complete" )
Common ICAP headers
Variables ¶
var (
DEBUG = false
)
the debug mode determiner & the writer to the write the debug output to
Functions ¶
func DumpRequest ¶
DumpRequest returns the given request in its ICAP/1.x wire representation.
func SetDebugMode ¶
func SetDebugMode(debug bool)
SetDebugMode sets the debug mode for the entire package depending on the bool
func SetDebugOutput ¶
SetDebugOutput sets writer to write the debug outputs (default: os.Stdout)
Types ¶
type Client ¶
Client represents the icap client who makes the icap server calls
func (*Client) DoRemaining ¶
DoRemaining requests an ICAP server with the remaining body bytes which did not fit in the preview in the original request
type Driver ¶
type Driver struct { Host string Port int DialerTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration // contains filtered or unexported fields }
Driver os the one responsible for driving the transport layer operations
func (*Driver) ConnectWithContext ¶
ConnectWithContext connects to the server satisfying the context
type Request ¶
type Request struct { Method string URL *url.URL Header http.Header HTTPRequest *http.Request HTTPResponse *http.Response ChunkLength int PreviewBytes int // contains filtered or unexported fields }
Request represents the icap client request data
func NewRequest ¶
func NewRequest(method, urlStr string, httpReq *http.Request, httpResp *http.Response) (*Request, error)
NewRequest is the factory function for Request
func (*Request) ExtendHeader ¶
ExtendHeader extends the current ICAP Request header with a new header
func (*Request) SetContext ¶
SetContext sets a context for the ICAP request
func (*Request) SetDefaultRequestHeaders ¶
func (r *Request) SetDefaultRequestHeaders()
SetDefaultRequestHeaders assigns some of the headers with its default value if they are not set already
func (*Request) SetPreview ¶
SetPreview sets the preview bytes in the icap header