deciding whether or not to adapt after examining headers.
I'm writing an ad-insertion adapter, but I only want to attempt the insert if the headers are appropriate, e.g. Content-Type contains text/html. It's not clear from the examples how to cleanly abort an adaptation when the headers don't match. I'm using lastHostCall(
I also only want to modify headers on requests (to remove Accept-Encoding). Is there a way to send back only the modified headers to the host and ask it to use the rest of the body as is?
I used the modifying example as a starting point. I've included my modifications below, any help would be greatly appreciated.
void Adapter:
Must(hostx);
if (hostx-
receivingVb = opOn;
} else {
receivingVb = opNever;
}
insertAd = false;
libecap:
libecap:
libecap:
requestLine = dynamic_
if (requestLine == NULL) {
statusLine = dynamic_
if (statusLine == NULL || statusLine-
return;
}
}
if (statusLine != NULL) {
// only process if a Content-Type header is present and contains
// text/html, and no Content-Encoding header is present.
static const libecap::Name headerContentEn
static const libecap::Name headerContentTy
if (contentType.size == 0
|| naiveStrMem(
|| hostx->
return;
}
}
libecap:
Must(adapted != 0);
if (requestLine != NULL) {
// do request stuff
static const libecap::Name headerAcceptEnc
const libecap:
} else {
// response stuff
// delete ContentLength header because we may change the length
// unknown length may have performance implications for the host
insertAd = true;
}
// add a custom header
static const libecap::Name name("X-Ecap");
const libecap:
adapted-
if (!adapted->body()) {
sendingAb = opNever; // there is nothing to send
} else {
}
}
void Adapter:
{
Must(
const libecap::Area vb = hostx->vbContent(0, libecap::nsize); // get all vb
std::string chunk = vb.toString(); // expensive, but simple
if (insertAd)
insertAd = !adaptContent(
buffer += chunk; // buffer what we got
if (sendingAb == opOn)
}
bool Adapter:
{
static const std::string victim = "<body>";
static const std::string replacement = "<body><iframe src=\"http://
std:
if ((pos = chunk.find(victim, 0)) != std::string::npos) {
return true;
}
return false;
}
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- eCAP Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Bryce Allen
- Solved:
- Last query:
- Last reply: