[4.0] 9f1222e More http_ cleanup:

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 24 11:31:54 CEST 2014


commit 9f1222ed48c3105ca395d88dc2d75ef77223da81
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 4 08:51:10 2014 +0000

    More http_ cleanup:
    
    Move policy decisions out where they belong and let the http_Filter
    function send the first like through unmolested.
    
    Rather than value specific functions, make a generic
    http_ForceField() function, because the name is cool.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 681c857..22e0362 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -996,7 +996,7 @@ void http_PrintfHeader(struct http *to, const char *fmt, ...)
     __printflike(2, 3);
 void http_SetHeader(struct http *to, const char *hdr);
 void http_SetH(const struct http *to, unsigned n, const char *fm);
-void http_ForceGet(const struct http *to);
+void http_ForceField(const struct http *to, unsigned n, const char *t);
 void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum VSL_tag_e);
 void http_Teardown(struct http *ht);
 int http_GetHdr(const struct http *hp, const char *hdr, char **ptr);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index a246985..ee1b0e5 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -79,8 +79,12 @@ ved_include(struct req *preq, const char *src, const char *host)
 		http_SetHeader(req->http0, host);
 	}
 
-	http_ForceGet(req->http0);
+	http_ForceField(req->http0, HTTP_HDR_METHOD, "GET");
+	http_ForceField(req->http0, HTTP_HDR_PROTO, "HTTP/1.1");
+
+	/* Don't allow Conditions, we can't use a 304 */
 	http_Unset(req->http0, H_If_Modified_Since);
+	http_Unset(req->http0, H_If_None_Match);
 
 	/* Client content already taken care of */
 	http_Unset(req->http0, H_Content_Length);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 450560c..c175e74 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -190,7 +190,8 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
 	    bo->do_pass ? HTTPH_R_PASS : HTTPH_R_FETCH);
 
 	if (!bo->do_pass) {
-		http_ForceGet(bo->bereq0);
+		http_ForceField(bo->bereq0, HTTP_HDR_METHOD, "GET");
+		http_ForceField(bo->bereq0, HTTP_HDR_PROTO, "HTTP/1.1");
 		if (cache_param->http_gzip_support)
 			http_ForceHeader(bo->bereq0, H_Accept_Encoding, "gzip");
 		AN(bo->req);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 1b17cac..1d1f872 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -545,6 +545,7 @@ http_PutField(struct http *to, int field, const char *string)
 	to->hdf[field] = 0;
 	http_VSLH(to, field);
 }
+
 /*--------------------------------------------------------------------*/
 
 void
@@ -559,13 +560,22 @@ http_SetH(const struct http *to, unsigned n, const char *fm)
 	http_VSLH(to, n);
 }
 
+/*--------------------------------------------------------------------
+ * Force a particular header field to a particular value
+ */
+
 void
-http_ForceGet(const struct http *to)
+http_ForceField(const struct http *to, unsigned n, const char *t)
 {
-	if (strcmp(http_GetReq(to), "GET"))
-		http_SetH(to, HTTP_HDR_METHOD, "GET");
+	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+	assert(n < HTTP_HDR_FIRST);
+	AN(t);
+	if (to->hd[n].b == NULL || strcmp(to->hd[n].b, t))
+		http_SetH(to, n, t);
 }
 
+/*--------------------------------------------------------------------*/
+
 void
 http_PutResponse(struct http *to, const char *proto, uint16_t status,
     const char *reason)
@@ -671,10 +681,7 @@ http_FilterReq(struct http *to, const struct http *fm, unsigned how)
 
 	http_linkh(to, fm, HTTP_HDR_METHOD);
 	http_linkh(to, fm, HTTP_HDR_URL);
-	if (how == HTTPH_R_FETCH)
-		http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
-	else
-		http_linkh(to, fm, HTTP_HDR_PROTO);
+	http_linkh(to, fm, HTTP_HDR_PROTO);
 	http_filterfields(to, fm, how);
 }
 
@@ -686,8 +693,8 @@ http_FilterResp(const struct http *fm, struct http *to, unsigned how)
 
 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
 	to->status = fm->status;
+	http_linkh(to, fm, HTTP_HDR_PROTO);
 	http_linkh(to, fm, HTTP_HDR_STATUS);
 	http_linkh(to, fm, HTTP_HDR_REASON);
 	http_filterfields(to, fm, how);
@@ -706,9 +713,9 @@ http_Merge(const struct http *fm, struct http *to, int not_ce)
 	const char *p;
 
 	to->status = fm->status;
-	http_SetH(to, HTTP_HDR_PROTO, fm->hd[HTTP_HDR_PROTO].b);
-	http_SetH(to, HTTP_HDR_STATUS, fm->hd[HTTP_HDR_STATUS].b);
-	http_SetH(to, HTTP_HDR_REASON, fm->hd[HTTP_HDR_REASON].b);
+	http_linkh(to, fm, HTTP_HDR_PROTO);
+	http_linkh(to, fm, HTTP_HDR_STATUS);
+	http_linkh(to, fm, HTTP_HDR_REASON);
 
 	for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
 		fm->hdf[u] |= HDF_MARKER;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index d14f398..4c8ca8e 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -103,6 +103,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
 	http_FilterResp(req->obj->http, req->resp, 0);
+	http_ForceField(req->resp, HTTP_HDR_PROTO, "HTTP/1.1");
 
 	if (req->wrk->stats.cache_hit)
 		http_PrintfHeader(req->resp,



More information about the varnish-commit mailing list