Overview
The IWebProxy is a lightweight, asynchronous proxy that intercepts and modifies network requests. It provides a flexible and efficient way to manage data flow and improve performance.
Core Concepts
- Request Interception: The IWebProxy intercepts all incoming HTTP requests.
- Data Transformation: It allows for modifying requests before sending them, customizing them for different destinations.
- Asynchronous Handling: It processes requests concurrently, improving responsiveness.
API Methods
- `init(options)`: Initializes the IWebProxy. Takes an optional `options` object.
- `intercept(request, response)`: Intercepts a request and sends a modified response.
- `modify(request, response, data)`: Modify a request before sending it.
- `send(data)`: Sends the data to the destination.
- `close()`: Gracefully shuts down the IWebProxy.
Example - Request Modification
Example: Modify a request to add a timestamp.
function modifyRequest(request, response, data) {
response.headers.set('X-Custom-Timestamp', new Date().getTime());
return response;
}
Example - Data Transfer
Example: Transfer data with a custom header.
function sendData(data) {
response.headers.append('Custom-Header', data);
return response;
}