MINOR: cache: Register the cache as a data filter only if response is cacheable

Instead of calling register_data_filter() when the stream analyze starts, we now
call it when we are sure the response is cacheable. It is done in the
http_headers callback, just before the body analyzis, and only if the headers
was already been cached. And during the body analyzis, if an error occurred or
if the response is too big, we unregistered the cache immediatly.

This patch may be backported in 1.8. It is not a bug but a significant
improvement.
diff --git a/src/cache.c b/src/cache.c
index e0905ef..437a908 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -144,8 +144,6 @@
 		filter->ctx     = st;
 	}
 
-	register_data_filter(s, chn, filter);
-
 	return 1;
 }
 
@@ -186,8 +184,10 @@
 	if (!(msg->chn->flags & CF_ISRESP) || !st)
 		return 1;
 
-	st->hdrs_len = msg->sov;
-
+	if (st->first_block) {
+		register_data_filter(s, msg->chn, filter);
+		st->hdrs_len = msg->sov;
+	}
 	return 1;
 }
 
@@ -219,8 +219,11 @@
 	 * We need to skip the HTTP headers first, because we saved them in the
 	 * http-response action.
 	 */
-	if (!(msg->chn->flags & CF_ISRESP) || !st)
+	if (!(msg->chn->flags & CF_ISRESP) || !st) {
+		/* should never happen */
+		unregister_data_filter(s, msg->chn, filter);
 		return len;
+	}
 
 	if (!len) {
 		/* Nothing to forward */
@@ -233,7 +236,7 @@
 	}
 	else {
 		/* Forward data */
-		if (filter->ctx && st->first_block) {
+		if (st->first_block) {
 			int to_append, append;
 			struct shared_block *fb;
 
@@ -244,6 +247,7 @@
 			if (!fb) {
 				shctx_unlock(shctx);
 				disable_cache_entry(st, filter, shctx);
+				unregister_data_filter(s, msg->chn, filter);
 				return len;
 			}
 			shctx_unlock(shctx);
@@ -256,11 +260,16 @@
 			/* Rewind the buffer to forward all data */
 			c_rew(msg->chn, st->hdrs_len);
 			st->hdrs_len = 0;
-			if (ret < 0)
+			if (ret < 0) {
 				disable_cache_entry(st, filter, shctx);
+				unregister_data_filter(s, msg->chn, filter);
+			}
 		}
-		else
+		else {
+			/* should never happen */
+			unregister_data_filter(s, msg->chn, filter);
 			ret = len;
+		}
 	}
 
 	if ((ret != len) ||