can eCap replace url_rewrite_program?

Asked by Tom

I currently have a simple eCap adapter. I now need to implement some form of basic URL rewriting. The Squid configuration for url_rewrite_program works perfectly well, but I would like to have all my logic and source in one place if possible. Is it possible for eCap to rewrite the URL in a reqmod?

I found the FAQ on how to get the requested uri (https://answers.launchpad.net/ecap/+faq/1576), but don't see anything which would indicate it is possible to rewrite it. I found this other post (http://www.squid-cache.org/mail-archive/squid-users/201009/0278.html) which indicates that eCap is called before url_rewrite_program, so perhaps it is possible.

Thanks in advance!

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
Best Alex Rousskov (rousskov) said :
#1

Yes, an eCAP adapter can modify any HTTP property of a message, including request URI and Host header.

Revision history for this message
Tom (web-l) said :
#2

Sure enough, it seems to work! Thanks.

I will say that I struggled for a bit to cast things properly so that it would work. I started with the code you offered somewhere else to get the URI:

 typedef const libecap::RequestLine *CLRLP;
 if (CLRLP requestLine = dynamic_cast<CLRLP>(&hostx->virgin().firstLine()))
  uri = requestLine->uri();
 else
 if (CLRLP requestLine = dynamic_cast<CLRLP>(&hostx->cause().firstLine()))
  uri = requestLine->uri();

The "const" declaration resulted in compiler errors when calling the method to set the uri. I finally ended up with the code below (hard-coded to google just for testing). The first lines getting the "adapted" variable were already part of adapter_modifying.cc, but I'm including them here so others may see the full context.

/* adapt message header */
libecap::shared_ptr<libecap::Message> adapted = hostx->virgin().clone();
Must(adapted != 0);

typedef libecap::RequestLine *CLRLP;
CLRLP requestLine = dynamic_cast<CLRLP>(&adapted->firstLine());
libecap::Area newURI = libecap::Area::FromTempString("http://www.google.com");
requestLine->uri(newURI);

Revision history for this message
Tom (web-l) said :
#3

Thanks Alex Rousskov, that solved my question.