[master] c52117a 1e3 status codes #1

Nils Goroll nils.goroll at uplex.de
Fri Dec 2 16:53:05 CET 2016


commit c52117a2d89a47a7a91970e2a75193eeec26d2a0
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Dec 2 14:32:49 2016 +0100

    1e3 status codes #1

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 5798374..dad7bd4 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -160,7 +160,7 @@ cnt_synth(struct worker *wrk, struct req *req)
 	now = W_TIM_real(wrk);
 	VSLb_ts_req(req, "Process", now);
 
-	if (req->err_code < 100 || req->err_code > 999)
+	if (req->err_code < 100)
 		req->err_code = 501;
 
 	HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index b829cd9..1abf5b7 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -54,11 +54,11 @@ VRT_synth(VRT_CTX, unsigned code, const char *reason)
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
-	if (code < 100 || code > 999)
+	if (code < 100)
 		code = 503;
 	ctx->req->err_code = (uint16_t)code;
-	ctx->req->err_reason =
-	    reason ? reason : http_Status2Reason(ctx->req->err_code, NULL);
+	ctx->req->err_reason = reason ? reason
+	    : http_Status2Reason(ctx->req->err_code % 1000, NULL);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishtest/tests/c00068.vtc b/bin/varnishtest/tests/c00068.vtc
index 08bda8d..313ca9b 100644
--- a/bin/varnishtest/tests/c00068.vtc
+++ b/bin/varnishtest/tests/c00068.vtc
@@ -20,14 +20,17 @@ varnish v1 -vcl+backend {
 		if (req.url == "/332") {
 			return (synth(332, "FOO"));
 		} else if (req.url == "/333") {
-			return (synth(resp.status, resp.reason));
+			return (synth(resp.status + 1000,
+				resp.reason));
 		} else {
 			return (synth(334, "BAR"));
 		}
 	}
 
 	sub vcl_synth {
-		if (resp.status == 333) {
+		# internal response status >1000 will be taken modulo
+		# 1000 when sent
+		if (resp.status == 1333) {
 			set resp.http.connection = "close";
 		} else if (resp.status == 332) {
 			if (req.restarts == 0) {
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index cc269f8..9ee7469 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -492,6 +492,9 @@ sp_variables = [
 		('backend_response', 'backend_error'),
 		('backend_response', 'backend_error'), """
 		The HTTP status code returned by the server.
+
+		Status codes >1000 can be set for vcl-internal
+		purposes and will be taken modulo 1000 on delivery.
 		"""
 	),
 	('beresp.reason',



More information about the varnish-commit mailing list