// nothing to do because we are using temporary buffers
// parsing; TODO: do not set until we parse, see ICAPOptXact
- icapReply = HTTPMSGLOCK(new HttpReply);
+ icapReply = new HttpReply;
icapReply->protoPrefix = "ICAP/"; // TODO: make an IcapReply class?
debugs(93,7, HERE << "initialized." << status());
{
Must(!state.serviceWaiting);
debugs(93, 7, HERE << "will wait for the ICAP service" << status());
- state.serviceWaiting = true;
typedef NullaryMemFunT<ModXact> Dialer;
AsyncCall::Pointer call = JobCallback(93,5,
Dialer, this, Adaptation::Icap::ModXact::noteServiceReady);
service().callWhenReady(call);
+ state.serviceWaiting = true; // after callWhenReady() which may throw
}
void Adaptation::Icap::ModXact::noteServiceReady()
// allocate the adapted message and copy metainfo
Must(!adapted.header);
- HttpMsg *newHead = NULL;
+ {
+ HttpMsg::Pointer newHead;
if (const HttpRequest *oldR = dynamic_cast<const HttpRequest*>(oldHead)) {
- HttpRequest *newR = new HttpRequest;
+ HttpRequest::Pointer newR(new HttpRequest);
newR->canonical = oldR->canonical ?
xstrdup(oldR->canonical) : NULL; // parse() does not set it
newHead = newR;
} else if (dynamic_cast<const HttpReply*>(oldHead)) {
- HttpReply *newRep = new HttpReply;
- newHead = newRep;
+ newHead = new HttpReply;
}
- Must(newHead);
+ Must(newHead != NULL);
+
newHead->inheritProperties(oldHead);
adapted.setHeader(newHead);
+ }
// parse the buffer back
http_status error = HTTP_STATUS_NONE;
- Must(newHead->parse(&httpBuf, true, &error));
+ Must(adapted.header->parse(&httpBuf, true, &error));
- Must(newHead->hdr_sz == httpBuf.contentSize()); // no leftovers
+ Must(adapted.header->hdr_sz == httpBuf.contentSize()); // no leftovers
httpBuf.clean();
debugs(93, 7, HERE << "cloned virgin message " << oldHead << " to " <<
- newHead);
+ adapted.header);
// setup adapted body pipe if needed
if (oldHead->body_pipe != NULL) {
mustStop("adapted body consumer aborted");
}
+Adaptation::Icap::ModXact::~ModXact()
+{
+ delete bodyParser;
+}
+
// internal cleanup
void Adaptation::Icap::ModXact::swanSong()
{
icapBuf.Printf("%s=%d, ", section, (int) httpBuf.contentSize());
// begin cloning
- HttpMsg *headClone = NULL;
+ HttpMsg::Pointer headClone;
if (const HttpRequest* old_request = dynamic_cast<const HttpRequest*>(head)) {
- HttpRequest* new_request = new HttpRequest;
- assert(old_request->canonical);
+ HttpRequest::Pointer new_request(new HttpRequest);
+ Must(old_request->canonical);
urlParse(old_request->method, old_request->canonical, new_request);
new_request->http_ver = old_request->http_ver;
headClone = new_request;
} else if (const HttpReply *old_reply = dynamic_cast<const HttpReply*>(head)) {
- HttpReply* new_reply = new HttpReply;
+ HttpReply::Pointer new_reply(new HttpReply);
new_reply->sline = old_reply->sline;
headClone = new_reply;
}
-
- Must(headClone);
+ Must(headClone != NULL);
headClone->inheritProperties(head);
HttpHeaderPos pos = HttpHeaderInitPos;
// pack polished HTTP header
packHead(httpBuf, headClone);
- delete headClone;
+ // headClone unlocks and, hence, deletes the message we packed
}
void Adaptation::Icap::ModXact::packHead(MemBuf &httpBuf, const HttpMsg *head)
// comm module read a portion of the ICAP response for us
void Adaptation::Icap::OptXact::handleCommRead(size_t)
{
- if (HttpMsg *r = parseResponse()) {
+ if (parseResponse()) {
icap_tio_finish = current_time;
setOutcome(xoOpt);
- sendAnswer(r);
- icapReply = HTTPMSGLOCK(dynamic_cast<HttpReply*>(r));
+ sendAnswer(icapReply);
Must(done()); // there should be nothing else to do
return;
}
scheduleRead();
}
-HttpMsg *Adaptation::Icap::OptXact::parseResponse()
+bool Adaptation::Icap::OptXact::parseResponse()
{
debugs(93, 5, HERE << "have " << readBuf.contentSize() << " bytes to parse" <<
status());
debugs(93, 5, HERE << "\n" << readBuf.content());
- HttpReply *r = HTTPMSGLOCK(new HttpReply);
+ HttpReply::Pointer r(new HttpReply);
r->protoPrefix = "ICAP/"; // TODO: make an IcapReply class?
- if (!parseHttpMsg(r)) { // throws on errors
- HTTPMSGUNLOCK(r);
- return 0;
- }
+ if (!parseHttpMsg(r)) // throws on errors
+ return false;
if (httpHeaderHasConnDir(&r->header, "close"))
reuseConnection = false;
- return r;
+ icapReply = r;
+ return true;
}
void Adaptation::Icap::OptXact::swanSong()