What adapter methods are called when a new request comes in?

Asked by Bob

Hi, Alex, I am new to ecap adapter writting, and I have checked the example code for several days, but I am still wondering where is the staring point for an adapter to work.

For instance, the following code excerpted from adapter_modifying.cc, which just registers an adapter into the host application, but after the registration, when a http request comes in, where is the first line to be executed for the adapter_modifying?

static const bool Registered = libecap::RegisterVersionedService(new Adapter::Service);

Question information

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

The sequence of calls often looks like this:

adapter::Service::wantsUrl() // the whole sequence terminates if this returns false
adapter::Service::makeXaction()
adapter::Xaction::Xaction()
adapter::Xaction::start()

After that, two groups of adapter::Xaction methods are called by the host application to deliver the virgin message body (if any) and/or to receive the adapted message body (if it was promised to the host):

/* virgin body delivery */
adapter::Xaction::noteVbContentAvailable() // often called many times
adapter::Xaction::noteVbContentDone()

/* adapted body delivery */
adapter::Xaction::makeAb()
adapter::Xaction::abContent() // often called many times
adapter::Xaction::abContentShift() // often called many times

Revision history for this message
Bob (362061693-k) said :
#2

thanks for your answer, Alex.

well, I have reviewed these three files: adapter_async.cc, adapter_minimal, adapter_modifying.cc, and found that there is always just one statement for their wantsUrl() functions, namely " return true", if it always returns true, why bother to say it ?

by the way, is adapter::Service::wantsUrl() called by the host application as the starting point? if so it just returns true, and afterwards, what will be executed next? the function of adapter::Service::makeXaction()? if so, who calls
adapter::Service::makeXaction()?

I have a lot of questions :)

Revision history for this message
Best Alex Rousskov (rousskov) said :
#3

> if it always returns true, why bother to say it ?

These are just simple sample adapters that focus on other parts of the API. Real adapters may return false in some cases. On the other hand, I do not know whether anybody is actually using this part of the API. When using Squid as the host application, it is easier (and probably better) to use a squid.conf ACL to control access instead.

> is adapter::Service::wantsUrl() called by the host application as the starting point? If so it just returns true, and afterwards, what will be executed next? the function of adapter::Service::makeXaction()?

Yes (to all of the above).

If wantsUrl() returns false, the host application does not call adapter::Service::makeXaction() for the current HTTP message \[at the current vectoring point\]. The wantsUrl() method was meant as a performance optimization -- it may take a lot of CPU cycles and some RAM to prepare the objects necessary for the makeXaction() call.

> who calls adapter::Service::makeXaction()?

The host application does (as you can verify by grepping host application and/or adapter and libecap sources).

> I have a lot of questions

In general, it is best to ask one question at a time, as a separate lp Question.

Revision history for this message
Bob (362061693-k) said :
#4

thanks Alex, I will close this question and open a new one.

Revision history for this message
Bob (362061693-k) said :
#5

Thanks Alex Rousskov, that solved my question.

Revision history for this message
qianguozheng (guozhengqian0825) said :
#6

@Alex, I saw your response about the sequence of the libecap, but I still not full understand how it works ? is there any detail description about that ?
I want to implement the function to support decompress gzip http response and insert script to it then compress it, after that send it to next hop.

Now, the question is adaptContent in ecap samples receive all the http response ? or it is just a chunk, if it is the whole response I can decompress it at adaptContent function, but if it is not , how to process that ?

I also don't know how to open the ecap log int squid, please give me some advice, thanks in advance.

Revision history for this message
Alex Rousskov (rousskov) said :
#7

> is there any detail description about that ?

I am not aware of any additional information not already published here, on e-cap.org site, or in the open sourced adapters.

> adaptContent in ecap samples receive all the http response ?

Xaction::adaptContent() in the modifying_adapter sample receives whatever the host application (e.g., Squid) wants to give to the adapter transaction at the time of the vbContent() call [by that adapter transaction]. In most cases involving large bodies, the adapter receives a part of the message body. Production-quality host applications do not buffer entire message bodies [on purpose].

Please note that Xaction::adaptContent() is a non-virtual method in the modifying_adapter sample. It is not a part of the eCAP API.

> if it is not [a whole response] , how to [decompress] that?

A good decompression library allows decompressing content streams, one piece or "chunk" at a time. You can also accumulate the whole body and decompress after that, of course.

> I also don't know how to open the ecap log int squid, please give me some advice.

adapter_async in the latest eCAP adapter sample has an eCap logging example. Search for "Debug". Squid uses debugging section 93 for eCAP debugging messages. See Squid's Adaptation::Ecap::Host::openDebug() for details on the eCAP-to-Squid debugging "level" conversion.