[master] 4d5a73b Don't frob http->status directly to test value, we need to take account for the extra two digits made available for VCL.

Poul-Henning Kamp phk at FreeBSD.org
Thu Aug 7 12:14:46 CEST 2014


commit 4d5a73ba3e75705657181706d216d37a7cdcbbfb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Aug 7 10:14:15 2014 +0000

    Don't frob http->status directly to test value, we need to take
    account for the extra two digits made available for VCL.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 78d84a6..810fe4e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -967,6 +967,7 @@ int http_GetHdrField(const struct http *hp, const char *hdr,
     const char *field, char **ptr);
 double http_GetHdrQ(const struct http *hp, const char *hdr, const char *field);
 uint16_t http_GetStatus(const struct http *hp);
+int http_IsStatus(const struct http *hp, int);
 void http_SetStatus(struct http *to, uint16_t status);
 const char *http_GetReq(const struct http *hp);
 int http_HdrIs(const struct http *hp, const char *hdr, const char *val);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 9a896fd..1c67e9a 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -203,7 +203,7 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
 		http_CopyHome(bo->bereq0);
 	}
 
-	if (bo->ims_obj != NULL && bo->ims_obj->http->status == 200) {
+	if (bo->ims_obj != NULL && http_IsStatus(bo->ims_obj->http, 200)) {
 		if (http_GetHdr(bo->ims_obj->http, H_Last_Modified, &p)) {
 			http_PrintfHeader(bo->bereq0,
 			    "If-Modified-Since: %s", p);
@@ -351,10 +351,10 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	AZ(bo->do_esi);
 
-	if (bo->ims_obj != NULL && bo->beresp->status == 304) {
+	if (bo->ims_obj != NULL && http_IsStatus(bo->beresp, 304)) {
 		http_Merge(bo->ims_obj->http, bo->beresp,
 		    bo->ims_obj->changed_gzip);
-		assert(bo->beresp->status == 200);
+		assert(http_IsStatus(bo->beresp, 200));
 		do_ims = 1;
 	} else
 		do_ims = 0;
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 54e14ab..79e2bd2 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -532,6 +532,15 @@ http_GetStatus(const struct http *hp)
 	return (hp->status);
 }
 
+int
+http_IsStatus(const struct http *hp, int val)
+{
+
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+	assert(val >= 100 && val <= 999);
+	return (val == (hp->status % 1000));
+}
+
 /*--------------------------------------------------------------------
  * Setting the status will also set the Reason appropriately
  */
diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index 743816b..f93d492 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -93,7 +93,7 @@ v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
-	assert(http_GetStatus(req->resp) == 200);
+	assert(http_IsStatus(req->resp, 200));
 
 	/* We must snapshot the length if we're streaming from the backend */
 	if (bo != NULL)
@@ -244,7 +244,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 		/* In ESI mode, we can't know the aggregate length */
 		req->res_mode &= ~RES_LEN;
 		req->res_mode |= RES_ESI;
-	} else if (req->resp->status == 304) {
+	} else if (http_IsStatus(req->resp, 304)) {
 		req->res_mode &= ~RES_LEN;
 		http_Unset(req->resp, H_Content_Length);
 		req->wantbody = 0;
@@ -308,7 +308,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 	    req->wantbody &&
 	    !(req->res_mode & (RES_ESI|RES_ESI_CHILD)) &&
 	    cache_param->http_range_support &&
-	    http_GetStatus(req->resp) == 200) {
+	    http_IsStatus(req->resp, 200)) {
 		http_SetHeader(req->resp, "Accept-Ranges: bytes");
 		if (http_GetHdr(req->http, H_Range, &r))
 			v1d_dorange(req, bo, r);
@@ -373,7 +373,7 @@ V1D_Deliver_Synth(struct req *req)
 	AN(req->synth_body);
 
 	req->res_mode = 0;
-	if (req->resp->status == 304) {
+	if (http_IsStatus(req->resp, 304)) {
 		req->res_mode &= ~RES_LEN;
 		http_Unset(req->resp, H_Content_Length);
 		req->wantbody = 0;
@@ -422,7 +422,7 @@ V1D_Deliver_Synth(struct req *req)
 	    req->wantbody &&
 	    !(req->res_mode & RES_ESI_CHILD) &&
 	    cache_param->http_range_support &&
-	    http_GetStatus(req->resp) == 200) {
+	    http_IsStatus(req->resp, 200)) {
 		http_SetHeader(req->resp, "Accept-Ranges: bytes");
 		if (http_GetHdr(req->http, H_Range, &r))
 			v1d_dorange(req, NULL, r);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 3be502c..3405a1a 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -163,7 +163,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	if (!(req->objcore->flags & OC_F_PASS)
 	    && req->esi_level == 0
-	    && http_GetStatus(req->resp) == 200
+	    && http_IsStatus(req->resp, 200)
 	    && req->http->conds && RFC2616_Do_Cond(req)) {
 		http_PutResponse(req->resp, "HTTP/1.1", 304, NULL);
 		req->wantbody = 0;
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 154b633..cddab7c 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -207,16 +207,17 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats)
 		return (BS_NONE);
 	}
 
-	if (hp->status <= 199) {
+	if (http_GetStatus(hp) <= 199) {
 		/*
 		 * 1xx responses never have a body.
 		 * [RFC2616 4.3 p33]
+		 * ... but we should never see them.
 		 */
 		stats->fetch_1xx++;
-		return (BS_NONE);
+		return (BS_ERROR);
 	}
 
-	if (hp->status == 204) {
+	if (http_IsStatus(hp, 204)) {
 		/*
 		 * 204 is "No Content", obviously don't expect a body.
 		 * [RFC2616 10.2.5 p60]
@@ -225,7 +226,7 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats)
 		return (BS_NONE);
 	}
 
-	if (hp->status == 304) {
+	if (http_IsStatus(hp, 304)) {
 		/*
 		 * 304 is "Not Modified" it has no body.
 		 * [RFC2616 10.3.5 p63]



More information about the varnish-commit mailing list