[4.0] 94e99cb Add a V1D_Deliver_Synth() for delivering synth vcl_error{} responses.

Poul-Henning Kamp phk at FreeBSD.org
Thu Mar 13 10:24:31 CET 2014


commit 94e99cb511c5d50108636197cb0001d5b9b32c92
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Mar 11 10:04:01 2014 +0000

    Add a V1D_Deliver_Synth() for delivering synth vcl_error{} responses.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e0f45c9..94fdf32 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -855,6 +855,8 @@ int HTTP1_IterateReqBody(struct req *req, req_body_iter_f *func, void *priv);
 
 /* cache_http1_deliver.c */
 void V1D_Deliver(struct req *);
+void V1D_Deliver_Synth(struct req *req);
+
 
 static inline int
 VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index c9f373a..5a3da11 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -271,7 +271,7 @@ V1D_Deliver(struct req *req)
 	    req->wantbody &&
 	    !(req->res_mode & (RES_ESI|RES_ESI_CHILD)) &&
 	    cache_param->http_range_support &&
-	    http_GetStatus(req->obj->http) == 200) {
+	    http_GetStatus(req->resp) == 200) {
 		http_SetHeader(req->resp, "Accept-Ranges: bytes");
 		if (http_GetHdr(req->http, H_Range, &r))
 			v1d_dorange(req, r);
@@ -318,3 +318,101 @@ V1D_Deliver(struct req *req)
 	if (WRW_FlushRelease(req->wrk) && req->sp->fd >= 0)
 		SES_Close(req->sp, SC_REM_CLOSE);
 }
+
+void
+V1D_Deliver_Synth(struct req *req)
+{
+	char *r;
+
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	AZ(req->obj);
+	AN(req->synth_body);
+
+	req->res_mode = 0;
+	if (req->resp->status == 304) {
+		req->res_mode &= ~RES_LEN;
+		http_Unset(req->resp, H_Content_Length);
+		req->wantbody = 0;
+	} else {
+		req->res_mode |= RES_LEN;
+		http_Unset(req->resp, H_Content_Length);
+		http_PrintfHeader(req->resp, "Content-Length: %zd",
+		    VSB_len(req->synth_body));
+	}
+
+	if (req->esi_level > 0) {
+		/* Included ESI object, always CHUNKED or EOF */
+		req->res_mode &= ~RES_LEN;
+		req->res_mode |= RES_ESI_CHILD;
+	}
+
+	if (!(req->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) {
+		/* We havn't chosen yet, do so */
+		if (!req->wantbody) {
+			/* Nothing */
+		} else if (req->http->protover >= 11) {
+			req->res_mode |= RES_CHUNKED;
+		} else {
+			req->res_mode |= RES_EOF;
+			req->doclose = SC_TX_EOF;
+		}
+	}
+	VSLb(req->vsl, SLT_Debug, "RES_MODE %x", req->res_mode);
+
+	if (!(req->res_mode & RES_LEN))
+		http_Unset(req->resp, H_Content_Length);
+
+	if (req->res_mode & RES_GUNZIP)
+		http_Unset(req->resp, H_Content_Encoding);
+
+	if (req->res_mode & RES_CHUNKED)
+		http_SetHeader(req->resp, "Transfer-Encoding: chunked");
+
+	http_SetHeader(req->resp,
+	    req->doclose ? "Connection: close" : "Connection: keep-alive");
+
+	req->vdps[0] = v1d_bytes;
+	req->vdp_nxt = 0;
+
+	if (
+	    req->wantbody &&
+	    !(req->res_mode & RES_ESI_CHILD) &&
+	    cache_param->http_range_support &&
+	    http_GetStatus(req->resp) == 200) {
+		http_SetHeader(req->resp, "Accept-Ranges: bytes");
+		if (http_GetHdr(req->http, H_Range, &r))
+			v1d_dorange(req, r);
+	}
+
+	WRW_Reserve(req->wrk, &req->sp->fd, req->vsl, req->t_resp);
+
+	/*
+	 * Send HTTP protocol header, unless interior ESI object
+	 */
+	if (!(req->res_mode & RES_ESI_CHILD))
+		req->acct_req.hdrbytes += HTTP1_Write(req->wrk, req->resp, 1);
+
+	if (req->res_mode & RES_CHUNKED)
+		WRW_Chunked(req->wrk);
+
+	if (!req->wantbody) {
+		/* This was a HEAD or conditional request */
+#if 0
+	XXX: Missing pretend GZIP for esi-children
+	} else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp) {
+		while (req->obj->objcore->busyobj)
+			(void)usleep(10000);
+		ESI_DeliverChild(req);
+#endif
+	} else {
+		(void)VDP_bytes(req, VDP_FLUSH, VSB_data(req->synth_body),
+		    VSB_len(req->synth_body));
+		(void)VDP_bytes(req, VDP_FINISH,  NULL, 0);
+	}
+
+	if (req->res_mode & RES_CHUNKED && !(req->res_mode & RES_ESI_CHILD))
+		WRW_EndChunk(req->wrk);
+
+	if (WRW_FlushRelease(req->wrk) && req->sp->fd >= 0)
+		SES_Close(req->sp, SC_REM_CLOSE);
+}



More information about the varnish-commit mailing list