void
clientReplyContext::processConditional(StoreIOBuffer &result)
{
- StoreEntry *e = http->storeEntry();
+ StoreEntry *const e = http->storeEntry();
if (e->getReply()->sline.status != HTTP_OK) {
debugs(88, 4, "clientReplyContext::processConditional: Reply code " <<
if (!r.flags.ims) {
// RFC 2616: if If-None-Match matched and there is no IMS,
- // reply with 412 Precondition Failed
- sendPreconditionFailedError();
+ // reply with 304 Not Modified or 412 Precondition Failed
+ sendNotModifiedOrPreconditionFailedError();
return;
}
- // otherwise check IMS below to decide if we reply with 412
+ // otherwise check IMS below to decide if we reply with 304 or 412
matchedIfNoneMatch = true;
}
}
if (matchedIfNoneMatch) {
- // If-None-Match matched, reply with 412 Precondition Failed
- sendPreconditionFailedError();
+ // If-None-Match matched, reply with 304 Not Modified or
+ // 412 Precondition Failed
+ sendNotModifiedOrPreconditionFailedError();
return;
}
// otherwise reply with 304 Not Modified
- const time_t timestamp = e->timestamp;
- HttpReply *const temprep = e->getReply()->make304();
- http->logType = LOG_TCP_IMS_HIT;
- removeClientStoreReference(&sc, http);
- createStoreEntry(http->request->method, request_flags());
- e = http->storeEntry();
- // Copy timestamp from the original entry so the 304
- // reply has a meaningful Age: header.
- e->timestamp = timestamp;
- e->replaceHttpReply(temprep);
- e->complete();
- /*
- * TODO: why put this in the store and then serialise it and
- * then parse it again. Simply mark the request complete in
- * our context and write the reply struct to the client side.
- */
- triggerInitialStoreRead();
+ sendNotModified();
}
}
startError(err);
}
+/// send 304 (Not Modified) to client
+void
+clientReplyContext::sendNotModified()
+{
+ StoreEntry *e = http->storeEntry();
+ const time_t timestamp = e->timestamp;
+ HttpReply *const temprep = e->getReply()->make304();
+ http->logType = LOG_TCP_IMS_HIT;
+ removeClientStoreReference(&sc, http);
+ createStoreEntry(http->request->method, request_flags());
+ e = http->storeEntry();
+ // Copy timestamp from the original entry so the 304
+ // reply has a meaningful Age: header.
+ e->timestamp = timestamp;
+ e->replaceHttpReply(temprep);
+ e->complete();
+ /*
+ * TODO: why put this in the store and then serialise it and
+ * then parse it again. Simply mark the request complete in
+ * our context and write the reply struct to the client side.
+ */
+ triggerInitialStoreRead();
+}
+
+/// send 304 (Not Modified) or 412 (Precondition Failed) to client
+/// depending on request method
+void
+clientReplyContext::sendNotModifiedOrPreconditionFailedError()
+{
+ if (http->request->method == METHOD_GET ||
+ http->request->method == METHOD_HEAD)
+ sendNotModified();
+ else
+ sendPreconditionFailedError();
+}
+
void
clientReplyContext::processReplyAccess ()
{