return HttpRequest::adaptHistory(loggingNeedsHistory);
}
+void
+HttpRequest::adaptHistoryImport(const HttpRequest &them)
+{
+ if (!adaptHistory_) {
+ adaptHistory_ = them.adaptHistory_; // may be nil
+ } else {
+ // check that histories did not diverge
+ Must(!them.adaptHistory_ || them.adaptHistory_ == adaptHistory_);
+ }
+}
+
#endif
bool
Adaptation::History::Pointer adaptLogHistory() const;
/// Returns possibly nil history, creating it if requested
Adaptation::History::Pointer adaptHistory(bool createIfNone = false) const;
+ /// Makes their history ours, throwing on conflicts
+ void adaptHistoryImport(const HttpRequest &them);
#endif
#if ICAP_CLIENT
/// Returns possibly nil history, creating it if icap logging is enabled
Must(r);
Adaptation::History::Pointer ah = r->adaptHistory();
- if (!ah)
+ if (!ah) {
+ debugs(85,9, HERE << "no history to store a service-proposed plan");
return false; // the feature is not enabled or is not triggered
+ }
String services;
if (!ah->extractNextServices(services)) { // clears history
// check that clone() copies the pipe so that we do not have to
Must(!theVirginRep.raw().header->body_pipe == !clone->body_pipe);
- updateHistory();
+ updateHistory(clone);
sendAnswer(Answer::Forward(clone));
Must(done());
}
HttpMsg *msg = answer().header;
if (!theAnswerRep->body()) { // final, bodyless answer
proxyingAb = opNever;
- updateHistory();
+ updateHistory(msg);
sendAnswer(Answer::Forward(msg));
} else { // got answer headers but need to handle body
proxyingAb = opOn;
rep->tieBody(this); // sets us as a producer
Must(msg->body_pipe != NULL); // check tieBody
- updateHistory();
+ updateHistory(msg);
sendAnswer(Answer::Forward(msg));
debugs(93,4, HERE << "adapter will produce body" << status());
sinkVb("blockVirgin");
- updateHistory();
+ updateHistory(NULL);
sendAnswer(Answer::Block(service().cfg().key));
Must(done());
}
/// Called just before sendAnswer() to record adapter meta-information
/// which may affect answer processing and may be needed for logging.
void
-Adaptation::Ecap::XactionRep::updateHistory()
+Adaptation::Ecap::XactionRep::updateHistory(HttpMsg *adapted)
{
if (!theMaster) // all updates rely on being able to query the adapter
return;
theMaster->visitEachOption(extractor);
ah->recordMeta(&meta);
}
+
+ // Add just-created history to the adapted/cloned request that lacks it.
+ if (HttpRequest *adaptedReq = dynamic_cast<HttpRequest*>(adapted))
+ adaptedReq->adaptHistoryImport(*request);
}