Sharing info from eCAP adapter with other adapters

Asked by Moti Berger

Hi

I have an env with Squid 4 with several ICAPs.
In this env, I set in squid.conf the following:

adaptation_masterx_shared_names X-My-Header

and I add an ICAP header X-My-Header with some data in one ICAP and next ICAPs can use it (I also see it in tcpdump output).

Now I'm writing an eCAP and I did the following (for testing):

static const libecap::Name myHeader("X-My-Header", libecap::Name::NextId());
const libecap::Area Adapter::Xaction::option(const libecap::Name &name) const
{
    if (name == myHeader) {
        std::string t = "popo";
        return libecap::Area(t.data(), t.size());
    }
    return libecap::Area();
}

void Adapter::Xaction::visitEachOption(libecap::NamedValueVisitor &visitor) const
{
    std::string t = "popo";
    visitor.visit(myHeader, libecap::Area(t.data(), t.size()));
}

It is much like the clamAV eCAP example.
What I see in tcpdump output is the following:

X.....qZREQMOD icap://my.proxy:1234/request ICAP/1.0
Host: my.proxy:1234
Date: Wed, 14 Jul 2021 20:37:33 GMT
X-My-Header: .
Encapsulated: req-hdr=0, null-body=427
Preview: 0
Allow: 204

Meaning, it indeed added the X-My-Header as ICAP header for the benefit of the ICAP server on the chain but it seems the value is just a dot. When I had to pass the data in X-My-Header from an ICAP server with ICAP header everything worked fine.
What am I doing wrong?

Thanks,
Moti

Question information

Language:
English Edit question
Status:
Answered
For:
eCAP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Alex Rousskov (rousskov) said :
#1

> if (name == myHeader) {
> std::string t = "popo";
> return libecap::Area(t.data(), t.size());

Would not t.data() lifetime _end_ before the caller can use the area object that this method creates and returns?

When created with just two parameters, Area relies on its creator/owner to keep memory around, similar to std::stringview. In the above code, that memory will be gone by the time the method returns because the "t" variable will be destroyed upon exit.

Can you help with this problem?

Provide an answer of your own, or ask Moti Berger for more information if necessary.

To post a message you must log in.