[master] bb603b3 Introduce a dedicated http_SetStatus() function.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jun 10 09:30:04 CEST 2014
commit bb603b3d1f9c76906bea167cab1c6cadd4f0df54
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jun 10 07:29:44 2014 +0000
Introduce a dedicated http_SetStatus() function.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 732bf9f..a79b224 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1001,6 +1001,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);
+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);
int http_IsHdr(const txt *hh, const char *hdr);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 8411e1f..8313007 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -552,6 +552,27 @@ http_GetStatus(const struct http *hp)
return (hp->status);
}
+/*--------------------------------------------------------------------*/
+
+void
+http_SetStatus(struct http *to, uint16_t status)
+{
+ char buf[4];
+
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ /*
+ * We allow people to use top digits for internal VCL
+ * signalling, but strip them from the ASCII version.
+ */
+ to->status = status;
+ status %= 1000;
+ assert(status >= 100);
+ bprintf(buf, "%03d", status);
+ http_PutField(to, HTTP_HDR_STATUS, buf);
+}
+
+/*--------------------------------------------------------------------*/
+
const char *
http_GetReq(const struct http *hp)
{
@@ -581,19 +602,11 @@ void
http_PutResponse(struct http *to, const char *proto, uint16_t status,
const char *reason)
{
- char buf[4];
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
- http_SetH(to, HTTP_HDR_PROTO, proto);
- /*
- * We allow people to use top digits for internal VCL
- * signalling, strip them here.
- */
- status %= 1000;
- assert(status >= 100);
- to->status = status;
- bprintf(buf, "%03d", status % 1000);
- http_PutField(to, HTTP_HDR_STATUS, buf);
+ if (proto != NULL)
+ http_SetH(to, HTTP_HDR_PROTO, proto);
+ http_SetStatus(to, status);
if (reason == NULL)
reason = http_Status2Reason(status);
http_SetH(to, HTTP_HDR_REASON, reason);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 3ce5817..b74e101 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -105,8 +105,9 @@ VRT_l_##obj##_status(const struct vrt_ctx *ctx, long num) \
VSLb(ctx->vsl, SLT_VCL_Error, "illegal %s.status (..0##)", \
#obj); \
ctx->http_##obj->failed = 1; \
- } else \
- ctx->http_##obj->status = (uint16_t)num; \
+ } else { \
+ http_SetStatus(ctx->http_##obj, (uint16_t)num); \
+ } \
}
#define VRT_STATUS_R(obj) \
More information about the varnish-commit
mailing list