how to modify request URI

Asked by qianguozheng on 2016-06-17

Hi Guys:

I know basic workflow of ecap now, and I can get its uri through below API calls, and also know how to add/remove header lines, like "Cookie", "Accept-Encoding", and so on.

But I still cannot figure out how to modify the http request first line's uri ?

Could you give me some example to do that ?

 thanks in advance.

if (requestLine = dynamic_cast<CLRLP>(&hostx->virgin().firstLine())) {
            uri = requestLine->uri();
    } else {
        if (requestLine = CLRLP(&hostx->cause().firstLine()))
                uri = requestLine->uri();
    }

Question information

Language:
English Edit question
Status:
Solved
For:
eCAP Edit question
Assignee:
No assignee Edit question
Solved by:
Alex Rousskov
Solved:
2016-06-21
Last query:
2016-06-21
Last reply:
2016-06-20

I tried with below method, but nothing works out.

typedef libecap::RequestLine *CLRLP;
CLRLP requestLine;
libecap::Area uri;

if (requestLine = dynamic_cast<CLRLP>(&hostx->virgin().firstLine())) {
     uri = requestLine->uri();
} else {
    if (requestLine = CLRLP(&hostx->cause().firstLine()))
           uri = requestLine->uri();
}
    libecap::Area newuri;
    std::string str = std::string("http://192.168.1.32/sample.html");
    newuri.FromTempString(str);
    //libecap::RequestLine
   requestLine->uri(newuri);

I refer to ClamAV, but could not find the one you provided in https://answers.launchpad.net/ecap/+question/186565
that generate a newResponse(), I can also try this if I found sample there.

Best Alex Rousskov (rousskov) said : #3

The correct method to use is RequestLine::uri(Area), as you have suspected.

Your adapter code does not work for several reasons:

1. You are trying to change the virgin message. That is wrong -- you cannot undo what already has happened. You need to clone() the virgin message, adjust the clone, and call useAdapted() instead.

2. The cause() code is accessing request URI in RESPMOD. That is pointless -- you cannot change the request when adapting the response to that request. If you want to change the URI, you must do it in REQMOD.

3. You apparently think that the static Area::FromTempString() will somehow change the `newuri` object. As a static method, it cannot change the object (and you should not access it via the object to avoid this confusion). You may do something like this:

    const libecap::Area newUri = Area::FromTempString("http://www.example.com/");

> I refer to ClamAV, but could not find the one you provided in https://answers.launchpad.net/ecap/+question/186565

The eCAP ClamAV adapter is available at http://www.e-cap.org/Downloads. Please note that the code cited in Answer #186565 may not exist in the newer ClamAV adapter versions because libecap v1.0 has a better blocking API available. Please also note that the ClamAV code created a brand new response while you want to adjust a request. That old ClamAV code is not very applicable to your situation!

@Alex,

I have followed you suggestion, and it works fine.

I am wondering if I want one ecap module support both REQMOD and RESPMOD, how could I distinguish between the request and reponse ?

Alex Rousskov (rousskov) said : #5

Please ask a new dedicated question instead of expanding this one. In your new question, please clarify whether you want to distinguish between two modes (REQMOD and RESPMOD) or the virgin message kind (request and response).

Thanks Alex Rousskov, that solved my question.