[master] 03d6df8 Allow to set (be)resp.body
Federico G. Schwindt
fgsch at lodoss.net
Mon Jun 27 19:23:07 CEST 2016
commit 03d6df890ade46c56d6dc8fc8dd9ce4a5dd7106e
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Fri Jun 24 09:12:56 2016 +0100
Allow to set (be)resp.body
This is equivalent to synthetic but using the more general set keyword.
diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index de237d6..259bebe 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -126,7 +126,7 @@ sub vcl_deliver {
sub vcl_synth {
set resp.http.Content-Type = "text/html; charset=utf-8";
set resp.http.Retry-After = "5";
- synthetic( {"<!DOCTYPE html>
+ set resp.body = {"<!DOCTYPE html>
<html>
<head>
<title>"} + resp.status + " " + resp.reason + {"</title>
@@ -140,7 +140,7 @@ sub vcl_synth {
<p>Varnish cache server</p>
</body>
</html>
-"} );
+"};
return (deliver);
}
@@ -173,7 +173,7 @@ sub vcl_backend_response {
sub vcl_backend_error {
set beresp.http.Content-Type = "text/html; charset=utf-8";
set beresp.http.Retry-After = "5";
- synthetic( {"<!DOCTYPE html>
+ set beresp.body = {"<!DOCTYPE html>
<html>
<head>
<title>"} + beresp.status + " " + beresp.reason + {"</title>
@@ -187,7 +187,7 @@ sub vcl_backend_error {
<p>Varnish cache server</p>
</body>
</html>
-"} );
+"};
return (deliver);
}
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index a16e88b..0667bde 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -689,6 +689,31 @@ VRT_r_resp_is_streaming(VRT_CTX)
/*--------------------------------------------------------------------*/
+#define VRT_BODY_L(which) \
+void \
+VRT_l_##which##_body(VRT_CTX, const char *str, ...) \
+{ \
+ va_list ap; \
+ const char *p; \
+ struct vsb *vsb; \
+ \
+ CAST_OBJ_NOTNULL(vsb, ctx->specific, VSB_MAGIC); \
+ va_start(ap, str); \
+ p = str; \
+ while (p != vrt_magic_string_end) { \
+ if (p == NULL) \
+ p = "(null)"; \
+ VSB_cat(vsb, p); \
+ p = va_arg(ap, const char *); \
+ } \
+ va_end(ap); \
+}
+
+VRT_BODY_L(beresp)
+VRT_BODY_L(resp)
+
+/*--------------------------------------------------------------------*/
+
#define HTTP_VAR(x) \
struct http * \
VRT_r_##x(VRT_CTX) \
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 4eaf69d..14c517f 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -455,6 +455,13 @@ sp_variables = [
The entire backend response HTTP data structure
"""
),
+ ('beresp.body',
+ 'BODY',
+ (),
+ ('backend_error',), """
+ The response body.
+ """
+ ),
('beresp.proto',
'STRING',
('backend_response', 'backend_error'),
@@ -685,6 +692,13 @@ sp_variables = [
The entire response HTTP data structure.
"""
),
+ ('resp.body',
+ 'BODY',
+ (),
+ ('synth',), """
+ The response body.
+ """
+ ),
('resp.proto',
'STRING',
('deliver', 'synth'),
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 9494cbc..dcdfc14 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -117,6 +117,8 @@ parse_set(struct vcc *tl)
vcc_Expr(tl, STRING_LIST);
} else if (fmt == STRING) {
vcc_Expr(tl, STRING_LIST);
+ } else if (fmt == BODY) {
+ vcc_Expr(tl, STRING_LIST);
} else {
vcc_Expr(tl, fmt);
}
More information about the varnish-commit
mailing list