How do I modify header after examining whole body?

Asked by Jinhee Lee on 2010-05-20

I'm writing keyword filtering module.
I think I need several functions to do this.

1. To access whole body.

2. Add custom header after examining the body to indicate there's a banned keyword.

3. To modify or replace whole body to be an error page.

I know how to access whole body. So I can do keyword filtering on the body. But I don't
know the rest of the things possible. Are they possible in current ECAP?

Thank you.

Question information

English Edit question
eCAP Edit question
No assignee Edit question
Solved by:
Alex Rousskov
Last query:
Last reply:
Alex Rousskov (rousskov) said : #1

Yes, all three adaptations are possible. To add a header, you can use libecap::Header::add method. The "modifying" adapter sample contains an X-Ecap header insertion example along with a body modification example.

It is not yet possible to use a proxy-provided error response, but that feature will be available in the future.

Jinhee Lee (jinyedge) said : #2

When I add a custom header in Adapter::Xaction::start() method like ecap_modifying sample
code it works fine. I did the same thing using ecap_passthru sample code and it works also fine.

After read some articles in this forum I found out how to accumulate body chunk and I could
access the whole body in Adapter::Xaction::noteVbContentDone(bool atEnd). And I tried to add
a custom header in that method but I couldn't see the header on squid side. I modified
in squid source file to print reply headers.

Do I need to do it in another method? Or am I missing something which should be done before
adding custom header like holding the adapted body chunks? It seems like I can't add any custom
header once some part of the body sent to squid.

I think ECAP approach is better than ICAP and I'm trying to replace some of our ICAP server.

Thank you,


Best Alex Rousskov (rousskov) said : #3

The adapter must send adapted headers before it sends the adapted body.
The adapter must adapt virgin headers before sending them to the host application.

Trailers aside, HTTP headers come before the body, so you cannot add to them after you start sending the body. This restriction is the same for both eCAP and ICAP.

If your adapted headers depend on the virgin body, you have to accumulate the virgin body until you can form the adapted headers and only then send the adapted headers (followed by the adapted body) to the host application.

Jinhee Lee (jinyedge) said : #4

Thanks Alex Rousskov, that solved my question.

Sandeep Kuttal (skuttal) said : #5

Hi Lee,

Can you suggest me how to accumulate whole of body of the message?