This repository contains a simple Node.js ICAP client implementation that supports OPTIONS and RESPMOD ICAP requests. It leverages Node.js's built-in net module to establish a TCP connection and send ICAP requests to an ICAP server. This client was designed to demonstrate antivirus file scanning capabilities and is part of a larger project available at antivirus-scan.mohammadyusuf.co.uk.
- OPTIONS Request: Sends an OPTIONS request to query the capabilities of the ICAP server.
- RESPMOD Request: Scans a file by sending a RESPMOD request to the ICAP server.
- Efficient File Handling: Handles both text-based and binary files for scanning.
- Customisable Configurations: Reads server details and timeouts from environment variables.
- Error Handling: Comprehensive logging and error reporting for seamless debugging.
icapClient.js: Contains the main logic for creating and sending OPTIONS and RESPMOD requests to the ICAP server.test.js: A simple test script to demonstrate scanning a file using the ICAP client.
net(built-in): Used to create a TCP client and communicate with the ICAP server.dotenv: For managing environment variables.fs: (built-in) For file handling in the test script.
The following environment variables are required to configure the ICAP client:
ICAP_SERVER_HOST: Hostname or IP address of the ICAP server.ICAP_SERVER_PORT: Port number of the ICAP server.ICAP_ENDPOINT: ICAP endpoint (e.g.,avscan).ICAP_SERVER_TIMEOUT: Optional. Timeout value for requests in milliseconds (default: 30000).
-
Install dependencies:
npm install
-
Set up the
.envfile:ICAP_SERVER_HOST=your-icap-server-host ICAP_SERVER_PORT=your-icap-server-port ICAP_ENDPOINT=your-icap-endpoint ICAP_SERVER_TIMEOUT=30000 -
Create a test file
Create a test file in the repository, and update test.js with the name and mime type.
-
Run the test script:
npm start
Visit the live demo of the antivirus scanning application: antivirus-scan.mohammadyusuf.co.uk.
Contributions are welcome! Feel free to submit issues or pull requests to enhance the functionality of this ICAP client.
MIT
For more details, contact me via my portfolio website: mohammadyusuf.co.uk.