[master] 5c1fea755 Move the 304 logic into a separate function for clarity.

Poul-Henning Kamp phk at FreeBSD.org
Mon Jan 13 09:12:06 UTC 2020


commit 5c1fea755361664d7f2f8e23e700a0e6a00f4225
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jan 13 09:11:06 2020 +0000

    Move the 304 logic into a separate function for clarity.

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 64e5ebf77..a8bede008 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -277,6 +277,43 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
 	return (F_STP_STARTFETCH);
 }
 
+/*--------------------------------------------------------------------
+ * 304 setup logic
+ */
+
+static int
+vbf_304_logic(struct busyobj *bo)
+{
+	if (bo->stale_oc != NULL &&
+	    ObjCheckFlag(bo->wrk, bo->stale_oc, OF_IMSCAND)) {
+		AZ(bo->stale_oc->flags & (OC_F_HFM|OC_F_PRIVATE));
+		if (ObjCheckFlag(bo->wrk, bo->stale_oc, OF_CHGCE)) {
+			/*
+			 * If a VFP changed C-E in the stored
+			 * object, then don't overwrite C-E from
+			 * the IMS fetch, and we must weaken any
+			 * new ETag we get.
+			 */
+			http_Unset(bo->beresp, H_Content_Encoding);
+			RFC2616_Weaken_Etag(bo->beresp);
+		}
+		http_Unset(bo->beresp, H_Content_Length);
+		HTTP_Merge(bo->wrk, bo->stale_oc, bo->beresp);
+		assert(http_IsStatus(bo->beresp, 200));
+		bo->was_304 = 1;
+	} else if (!bo->do_pass) {
+		/*
+		 * Backend sent unallowed 304
+		 */
+		VSLb(bo->vsl, SLT_Error,
+		    "304 response but not conditional fetch");
+		bo->htc->doclose = SC_RX_BAD;
+		vbf_cleanup(bo);
+		return (-1);
+	}
+	return (1);
+}
+
 /*--------------------------------------------------------------------
  * Setup bereq from bereq0, run vcl_backend_fetch
  */
@@ -383,35 +420,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	AZ(bo->do_esi);
 	AZ(bo->was_304);
 
-	if (http_IsStatus(bo->beresp, 304)) {
-		if (bo->stale_oc != NULL &&
-		    ObjCheckFlag(bo->wrk, bo->stale_oc, OF_IMSCAND)) {
-			AZ(bo->stale_oc->flags & (OC_F_HFM|OC_F_PRIVATE));
-			if (ObjCheckFlag(bo->wrk, bo->stale_oc, OF_CHGCE)) {
-				/*
-				 * If a VFP changed C-E in the stored
-				 * object, then don't overwrite C-E from
-				 * the IMS fetch, and we must weaken any
-				 * new ETag we get.
-				 */
-				http_Unset(bo->beresp, H_Content_Encoding);
-				RFC2616_Weaken_Etag(bo->beresp);
-			}
-			http_Unset(bo->beresp, H_Content_Length);
-			HTTP_Merge(bo->wrk, bo->stale_oc, bo->beresp);
-			assert(http_IsStatus(bo->beresp, 200));
-			bo->was_304 = 1;
-		} else if (!bo->do_pass) {
-			/*
-			 * Backend sent unallowed 304
-			 */
-			VSLb(bo->vsl, SLT_Error,
-			    "304 response but not conditional fetch");
-			bo->htc->doclose = SC_RX_BAD;
-			vbf_cleanup(bo);
-			return (F_STP_ERROR);
-		}
-	}
+	if (http_IsStatus(bo->beresp, 304) && vbf_304_logic(bo) < 0)
+		return (F_STP_ERROR);
 
 	VCL_backend_response_method(bo->vcl, wrk, NULL, bo, NULL);
 


More information about the varnish-commit mailing list