- Introduction
- Functions
GeneralFunc is a struct used to help developer who implement a new service of a new vendor. It has a lot of functions that the developer may need, they help him to do some tasks. These tasks are explained in that file.
type GeneralFunc struct {
httpMsg *http_message.HttpMsg
xICAPMetadata string
}
So the developer can add GeneralFunc field in the struct of the service which he implements, like Echo service, a field from type GeneralFunc is defined as the last field in Echo service struct as shown below.
type Echo struct {
xICAPMetadata string
httpMsg *http_message.HttpMsg
elapsed time.Duration
serviceName string
methodName string
maxFileSize int
bypassExts []string
processExts []string
rejectExts []string
extArrs []services_utilities.Extension
returnOrigIfMaxSizeExc bool
return400IfFileExtRejected bool
generalFunc *general_functions.GeneralFunc //GeneralFunc field
}
First, let's discuss about the only field in GeneralFunc which is an instance from type HttpMsg.
type HttpMsg struct {
Request *http.Request
Response *http.Response
}
HttpMsg is a struct which contains two fields. The first field is HTTP reauest and the second is HTTP response. It's used to encapsulate the HTTP request and response with each other because there are two modes in ICAP, REQMOD and RESPMOD.
HttpMsg field in GeneralFunc struct facilitates GeneralFunc dealing with HTTP request and response.
xICAPMetadata is a string value of the ID of ICAP request sent to ICAPeg.
-
-
It extracts the body of the HTTP message and get the content type of the body if it exists.
-
- methodName (string): possible values are (REQMOD and RESPMOD).
-
Return Values
- Pointer from bytes.Buffer type which points to the body of the HTTP message.
- Instance from ContentType type which is used as indicator to the content type of the body in case of REQMOD, but in case of RESPMOD it will be nil. This value is important when we prepare the HTTP request to return it to the client.
- Instance from error type to indicate if there is an error or not, the value will be nil if there is no error.
-
-
-
It extracts the body of the HTTP message and gets the content type of the body if it exists.
-
- fileExtension (string): The extension of the file.
- extArrs ([]services_utilities.Extension): Array of Extension type stores all information about extensions arrays (bypass, reject and process).
- processExts ([]string): Array of extensions which wanted to be processed.
- rejectExts ([]string): Array of extensions which wanted to be rejected.
- bypassExts ([]string): Array of extensions which wanted to be bypassed.
- return400IfFileExtRejected (bool): Bool variable indicates if the service configuration aims to return 400 as an ICAP response status in case the current file extension is rejected.
- isGzip (bool): Boolean variable indicates to if the HTTP message body was compressed in the HTTP message before starting processing.
- serviceName (string): The name of the service which you implement.
- methodName (string): possible values are (REQMOD and RESPMOD).
- identifier (string): The identifier of the service (service API identifier for example).
- requestURI (string): The requested URL that may cause getting a block page in case the file extension is rejected.
- reqContentType (ContentType): the content type of the HTTP message body before processing (multipart for example).
- file (*bytes.Buffer): The body of HTTP message.
-
- Bool variable, possible values are true if the file extension exists in process extension.
- Integer variable which is ICAP status should be returned from Processing function. It equals zero if the file extension exists in the process extensions array.
- Instance from error type to indicate if there is an error or not, the value will be nil if there is no error.
-
-
-
It checks if the body of an HTTP message is compressed in Gzip.
-
- methodName (string): possible values are (REQMOD and RESPMOD).
-
- Bool variable, possible values are true if the body is compressed in Gzip and false if the body is not.
-
-
-
It prepares and returns error page specified to the service included in http request to replace the original HTTP request with the new one (HTTP request with error page).
-
- reason (string): The reason of returning this HTML error page and this reason will be typed in the page.
- serviceName (string): The service's name which uses this function and this service name will be typed in the page.
- serviceName (string): The service's identifier which uses this function and this service identifier will be typed in the page.
-
- Instance from *bytes.Buffer type which is the HTML page converted to bytes.Buffer type to be included later inside the new HTTP request.
- Instance from *http.Request type which is the new HTTP request of the error page.
- Instance from error type to indicate whether there is an error or not, the value will be nil if there is no error.
-
-
-
It decompresses the file is compressed in Gzip.
-
- file (*bytes.Buffer): The body of HTTP message.
- Instance from bytes.Buffer type which is the file after decompression.
- Instance from error type to indicate if there is an error or not, the value will be nil if there is no error.
-
-
-
It takes the actions which should be taken if the body of the HTTP message.
-
- returnOrigIfMaxSizeExc (bool): The bool variable indicates if the service configuration aims to return the Original file in case the HTTP message body exceeds the max file size.
- serviceName (string): The name of the service which you implement.
- file (*bytes.Buffer): The body of HTTP message.
-
- Integer variable which is ICAP status should be returned from Processing function.
- Pointer from bytes.Buffer which is a body of the HTTP message should be returned from Processing function.
- interface{} which is the HTTP message which should be returned from Processing function.
-
-
-
It gets the file name from the HTTP message.
-
No parameters.
-
- String value stores the name of the file. if the file name doesn't exist in the requested URL of the HTTP message, the file name will be unnamed_file.
-
-
-
It's used to compress the body of the HTTP message body.
-
- scannedFile ([]byte): Array of bytes which contains the file which you want to compress.
-
- []byte array of bytes contains the body of HTTP message after compression.
- Instance from error type to indicate whether there is an error or not, the value will be nil if there is no error.
-
-
-
It prepares headers and status code of HTTP response which will include a block page as HTML file.
-
- status (int): The status of the HTTP response.
- pageContentLength (int): The content length of the HTML page.
-
- Pointer to http.Response type.
-
-
-
It returns a block page as an HTML page.
-
- path (string): The path of the block page.
- reason (string): The reason for getting a block page.
- serviceName (string): The name of the service which you implement.
- identifierId (string): The identifier of the service (service API identifier for example).
- reqUrl (string): The requested URL that causes getting a block page.
-
- Pointer to bytes.Buffer type which stores the block page.
-
-
-
It's used for preparing the HTTP response before returning it. It's used for REQMOD only.
-
- scannedFile ([]byte): Array of bytes which contains the file which you want to prepare.
- reqContentType (ContentType): the content type of the HTTP message body before processing (multipart for example).
- methodName (string): possible values are (REQMOD and RESPMOD).
-
- []byte array of bytes stores the file after scanning.
-
-
-
it handles the HTTP message if the status should be 204 no modifications.
-
- methodName (string): Possible values are (REQMOD and RESPMOD).
- status (int): The status of the HTTP response.
- file (*bytes.Buffer): The body of HTTP message.
- isGzip (bool): Boolean variable indicates to if the HTTP message body was compressed in the HTTP message before starting processing.
- reqContentType (ContentType): the content type of the HTTP message body before processing (multipart for example).
- httpMessage interface{}: The HTTP message which should be returned from Processing function.
-
- []byte array of bytes stores the file after the function finishes handling HTTP message.
- interface{} which is the HTTP message which should be returned from Processing function after the function finishes handling HTTP message.
-
-
-
It returns the suitable HTTP message (HTTP request, HTTP response).
-
- methodName (string): possible values are (REQMOD and RESPMOD).
- file (*bytes.Buffer): The file which wanted to be included in HTTP message.
-
- interface{} which is the HTTP message which should be returned from Processing function.
-
-
IfICAPStatusIs204
-
Description
It prepares the HTTP message if the ICAP status code is 204.
-
- methodName (string): possible values are (REQMOD and RESPMOD).
- status (int): The status of the ICAP response.
- file (*bytes.Buffer): The body of HTTP message.
- isGzip (bool): Boolean variable indicates to if the HTTP message body was compressed in the HTTP message before starting processing.
- reqContentType (ContentType): the content type of the HTTP message body before processing (multipart for example).
- httpMessage interface{}: The HTTP message which should be returned from Processing function.
-
- []byte which is array of bytes contains the body of the HTTP message.
- interface{} which is the HTTP message which should be returned from Processing function.
-
-
GetDecodedImage
-
Description
It takes the HTTP file and converts it to an image object.
-
- file (*bytes.Buffer): The body of file.
-
- Instance from image.Image type which is the file after converted to image object.
- Instance from error type to indicate if there is an error or not, the value will be nil if there is no error.
-
-
InitSecure
-
Description
It sets insecure flag based on user input
-
- VerifyServerCert (bool): The body of file.
-
- Instance from bool indicates to is the scure flag is true or false.
-
-
GetMimeExtension
-
Description
It returns the mime type extension of the data
-
- data ([]byte): The file in bytes.
- contentType (string): The content type of the data.
- filename (string): the name of the data.
-
- Instance from string indicates to is the mime type extension of the data.
-
-
LogHTTPMsgHeaders
-
Description
It returns the HTTP message headers as a map.
-
- methodName (string): possible values are (REQMOD and RESPMOD).
-
- Instance from map[string]interface{} contains the header of the HTTP message.
-