Yes, it can. Producing responses instead of adapting virgin requests is called "request satisfaction" in ICAP terminology, and eCAP supports that mode of operation. There are currently two ways to tell the host application to satisfy a virgin request with an adapted response (instead of forwarding a request to the next hop):
* libecap::Host::Xaction::blockVirgin(): Tells the host to "block" the request. What happens next depends on the host application, but it can be expected that the client will receive some kind of an error message. Usually, such responses are configurable. For example, Squid has deny_info option that can be used to specify what "blocking message" should be served to the client (it has an ability to serve a redirect message as well). Follow Adapter::Xaction::onVirus() in the eCAP ClamAV adapter for an implementation example.
* libecap::Host::Xaction::useAdapted(response): Tells the host to send the provided response headers (possibly followed by response body). The same API is used for regular message adaptation. In request satisfaction mode, you supply a from-scratch built response while receiving a virgin request (REQMOD). To create a response message in REQMOD, use the libecap::Host::newResponse() method. Here is how the eCAP ClamAV adapter used this API to block requests before blockVirgin() was available:
void Adapter::Xaction::useForbiddenMessage(...)
{
....
libecap::shared_ptr<libecap::Message> adapted = MyHost().newResponse();
Must(adapted != 0);
adapted->addBody();
StatusLine &statusLine = dynamic_cast<StatusLine&>(adapted->firstLine());
statusLine.statusCode(403);
statusLine.reasonPhrase(libecap::Area::FromTempString("Forbidden"));
adapted->header().add(headerContentType, libecap::Area::FromTempString("text/html"));
adapted->header().add(headerContentLength, ...);
hostx->useAdapted(adapted);
// expect abMake() and then abContent() calls
}
Please note that request satisfaction is used less often than regular adaptation so the underlying host code may be of lower quality.