return data_hdr.endOffset();
}
+void
+MemObject::markEndOfReplyHeaders()
+{
+ const int hdr_sz = endOffset();
+ assert(hdr_sz >= 0);
+ assert(_reply);
+ _reply->hdr_sz = hdr_sz;
+}
+
int64_t
MemObject::size() const
{
void replaceHttpReply(HttpReply *newrep);
void stat (MemBuf * mb) const;
int64_t endOffset () const;
+ void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
/// negative if unknown; otherwise, expected object_sz, expected endOffset
/// maximum, and stored reply headers+body size (all three are the same)
int64_t expectedReplySize() const;
assert(rep);
theFinalReply = HTTPMSGLOCK(rep);
- haveParsedReplyHeaders();
- entry->replaceHttpReply(theFinalReply);
+ // give entry the reply because haveParsedReplyHeaders() expects it there
+ entry->replaceHttpReply(theFinalReply, false); // but do not write yet
+ haveParsedReplyHeaders(); // update the entry/reply (e.g., set timestamps)
+ entry->startWriting(); // write the updated entry to store
return theFinalReply;
}
virtual void complete();
virtual store_client_t storeClientType() const;
virtual char const *getSerialisedMetaData();
- virtual void replaceHttpReply(HttpReply *);
+ void replaceHttpReply(HttpReply *, bool andStartWriting = true);
+ void startWriting(); ///< pack and write reply headers and, maybe, body
virtual bool swapoutPossible();
virtual void trimMemory();
void abort();
* NOTE: max-stale config blocks the overrides.
*/
int max_stale = (R->max_stale >= 0 ? R->max_stale : Config.maxStale);
- if ( max_stale >= 0 && staleness < max_stale) {
+ if ( max_stale >= 0 && staleness > max_stale) {
debugs(22, 3, "refreshCheck: YES: max-stale limit");
if (request)
request->flags.fail_on_validation_err = 1;
* a new reply. This eats the reply.
*/
void
-StoreEntry::replaceHttpReply(HttpReply *rep)
+StoreEntry::replaceHttpReply(HttpReply *rep, bool andStartWriting)
{
debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
- Packer p;
if (!mem_obj) {
debugs(20, 0, "Attempt to replace object with no in-memory representation");
mem_obj->replaceHttpReply(rep);
+ if (andStartWriting)
+ startWriting();
+}
+
+
+void
+StoreEntry::startWriting()
+{
+ Packer p;
+
/* TODO: when we store headers serparately remove the header portion */
/* TODO: mark the length of the headers ? */
/* We ONLY want the headers */
packerToStoreInit(&p, this);
assert (isEmpty());
+ assert(mem_obj);
+
+ const HttpReply *rep = getReply();
+ assert(rep);
- getReply()->packHeadersInto(&p);
-
- rep->hdr_sz = mem_obj->endOffset();
+ rep->packHeadersInto(&p);
+ mem_obj->markEndOfReplyHeaders();
- httpBodyPackInto(&getReply()->body, &p);
+ httpBodyPackInto(&rep->body, &p);
packerClean(&p);
}