[3.0] 93686f8 Move the function which checks if we can do condiitional (304) delivery into the RFC policy module where it belongs.

Tollef Fog Heen tfheen at varnish-cache.org
Wed Aug 17 11:27:45 CEST 2011


commit 93686f8515b31dd0f1659e535872a97b0c214e0a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 10 12:15:42 2011 +0000

    Move the function which checks if we can do condiitional (304) delivery
    into the RFC policy module where it belongs.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 2d04724..209dfc0 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -937,6 +937,7 @@ unsigned WS_Free(const struct ws *ws);
 double RFC2616_Ttl(const struct sess *sp);
 enum body_status RFC2616_Body(const struct sess *sp);
 unsigned RFC2616_Req_Gzip(const struct sess *sp);
+int RFC2616_Do_Cond(const struct sess *sp);
 
 /* storage_synth.c */
 struct vsb *SMS_Makesynth(struct object *obj);
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 0c306df..3cd7911 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -86,45 +86,8 @@ res_do_304(struct sess *sp)
 
 /*--------------------------------------------------------------------*/
 
-static int
-res_do_conds(struct sess *sp)
-{
-	char *p, *e;
-	double ims;
-	int do_cond = 0;
-
-	/* RFC 2616 13.3.4 states we need to match both ETag
-	   and If-Modified-Since if present*/
-
-	if (http_GetHdr(sp->http, H_If_Modified_Since, &p) ) {
-		if (!sp->obj->last_modified)
-			return (0);
-		ims = TIM_parse(p);
-		if (ims > sp->t_req)	/* [RFC2616 14.25] */
-			return (0);
-		if (sp->obj->last_modified > ims)
-			return (0);
-		do_cond = 1;
-	}
-
-	if (http_GetHdr(sp->http, H_If_None_Match, &p) &&
-	    http_GetHdr(sp->obj->http, H_ETag, &e)) {
-		if (strcmp(p,e) != 0)
-			return (0);
-		do_cond = 1;
-	}
-
-	if (do_cond == 1) {
-		res_do_304(sp);
-		return (1);
-	}
-	return (0);
-}
-
-/*--------------------------------------------------------------------*/
-
 static void
-res_dorange(struct sess *sp, const char *r, ssize_t *plow, ssize_t *phigh)
+res_dorange(const struct sess *sp, const char *r, ssize_t *plow, ssize_t *phigh)
 {
 	ssize_t low, high, has_low;
 
@@ -196,8 +159,10 @@ RES_BuildHttp(struct sess *sp)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
-	if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
+	if (sp->obj->response == 200 && sp->http->conds && RFC2616_Do_Cond(sp)) {
+		res_do_304(sp);
 		return;
+	}
 
 	http_ClrHeader(sp->wrk->resp);
 	sp->wrk->resp->logtag = HTTP_Tx;
diff --git a/bin/varnishd/rfc2616.c b/bin/varnishd/rfc2616.c
index 045eacb..eb01850 100644
--- a/bin/varnishd/rfc2616.c
+++ b/bin/varnishd/rfc2616.c
@@ -306,3 +306,36 @@ RFC2616_Req_Gzip(const struct sess *sp)
 	/* Bad client, no gzip. */
 	return (0);
 }
+
+/*--------------------------------------------------------------------*/
+
+int
+RFC2616_Do_Cond(const struct sess *sp)
+{
+	char *p, *e;
+	double ims;
+	int do_cond = 0;
+
+	/* RFC 2616 13.3.4 states we need to match both ETag
+	   and If-Modified-Since if present*/
+
+	if (http_GetHdr(sp->http, H_If_Modified_Since, &p) ) {
+		if (!sp->obj->last_modified)
+			return (0);
+		ims = TIM_parse(p);
+		if (ims > sp->t_req)	/* [RFC2616 14.25] */
+			return (0);
+		if (sp->obj->last_modified > ims)
+			return (0);
+		do_cond = 1;
+	}
+
+	if (http_GetHdr(sp->http, H_If_None_Match, &p) &&
+	    http_GetHdr(sp->obj->http, H_ETag, &e)) {
+		if (strcmp(p,e) != 0)
+			return (0);
+		do_cond = 1;
+	}
+
+	return (do_cond);
+}



More information about the varnish-commit mailing list