r5376 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Fri Oct 1 10:50:43 CEST 2010


Author: phk
Date: 2010-10-01 10:50:43 +0200 (Fri, 01 Oct 2010)
New Revision: 5376

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Isolate the text-representation of the HTTP response status field in
http_cache.h, and use the integer representation everywhere else.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-10-01 08:29:36 UTC (rev 5375)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-10-01 08:50:43 UTC (rev 5376)
@@ -65,6 +65,11 @@
 #include "vsc.h"
 #include "vsl.h"
 
+/*
+ * NB: HDR_STATUS is only used in cache_http.c, everybody else uses the
+ * http->status integer field.
+ */
+
 enum {
 	/* Fields from the first line of HTTP proto */
 	HTTP_HDR_REQ,
@@ -551,15 +556,15 @@
 void HTTP_Init(void);
 void http_ClrHeader(struct http *to);
 unsigned http_Write(struct worker *w, const struct http *hp, int resp);
-void http_CopyResp(const struct http *to, const struct http *fm);
-void http_SetResp(const struct http *to, const char *proto, const char *status,
+void http_CopyResp(struct http *to, const struct http *fm);
+void http_SetResp(struct http *to, const char *proto, int status,
     const char *response);
 void http_FilterFields(struct worker *w, int fd, struct http *to,
     const struct http *fm, unsigned how);
 void http_FilterHeader(const struct sess *sp, unsigned how);
 void http_PutProtocol(struct worker *w, int fd, const struct http *to,
     const char *protocol);
-void http_PutStatus(struct worker *w, int fd, struct http *to, int status);
+void http_PutStatus(struct http *to, int status);
 void http_PutResponse(struct worker *w, int fd, const struct http *to,
     const char *response);
 void http_PrintfHeader(struct worker *w, int fd, struct http *to,

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2010-10-01 08:29:36 UTC (rev 5375)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2010-10-01 08:50:43 UTC (rev 5376)
@@ -354,7 +354,7 @@
 		sp->err_code = 501;
 
 	http_PutProtocol(w, sp->fd, h, "HTTP/1.1");
-	http_PutStatus(w, sp->fd, h, sp->err_code);
+	http_PutStatus(h, sp->err_code);
 	TIM_format(TIM_real(), date);
 	http_PrintfHeader(w, sp->fd, h, "Date: %s", date);
 	http_PrintfHeader(w, sp->fd, h, "Server: Varnish");

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2010-10-01 08:29:36 UTC (rev 5375)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2010-10-01 08:50:43 UTC (rev 5376)
@@ -337,7 +337,6 @@
 http_GetStatus(const struct http *hp)
 {
 
-	Tcheck(hp->hd[HTTP_HDR_STATUS]);
 	return (hp->status);
 }
 
@@ -615,24 +614,24 @@
 }
 
 void
-http_CopyResp(const struct http *to, const struct http *fm)
+http_CopyResp(struct http *to, const struct http *fm)
 {
 
 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
-	http_copyh(to, fm, HTTP_HDR_STATUS);
+	to->status = fm->status;
 	http_copyh(to, fm, HTTP_HDR_RESPONSE);
 }
 
 void
-http_SetResp(const struct http *to, const char *proto, const char *status,
+http_SetResp(struct http *to, const char *proto, int status,
     const char *response)
 {
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	http_SetH(to, HTTP_HDR_PROTO, proto);
-	http_SetH(to, HTTP_HDR_STATUS, status);
+	to->status = status;
 	http_SetH(to, HTTP_HDR_RESPONSE, response);
 }
 
@@ -828,13 +827,10 @@
 }
 
 void
-http_PutStatus(struct worker *w, int fd, struct http *to, int status)
+http_PutStatus(struct http *to, int status)
 {
-	char stat[4];
 
 	assert(status >= 0 && status <= 999);
-	sprintf(stat, "%d", status);
-	http_PutField(w, fd, to, HTTP_HDR_STATUS, stat);
 	to->status = status;
 }
 
@@ -915,11 +911,18 @@
 	unsigned u, l;
 
 	if (resp) {
-		AN(hp->hd[HTTP_HDR_STATUS].b);
 		l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " ");
 		WSLH(w, *w->wfd, hp, HTTP_HDR_PROTO);
+
+		hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(w->ws, 4);
+		AN(hp->hd[HTTP_HDR_STATUS].b);
+
+		sprintf(hp->hd[HTTP_HDR_STATUS].b, "%3d", hp->status);
+		hp->hd[HTTP_HDR_STATUS].e = hp->hd[HTTP_HDR_STATUS].b + 3;
+
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " ");
 		WSLH(w, *w->wfd, hp, HTTP_HDR_STATUS);
+
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n");
 		WSLH(w, *w->wfd, hp, HTTP_HDR_RESPONSE);
 	} else {

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2010-10-01 08:29:36 UTC (rev 5375)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2010-10-01 08:50:43 UTC (rev 5376)
@@ -51,7 +51,7 @@
 
 	http_ClrHeader(sp->wrk->resp);
 	sp->wrk->resp->logtag = HTTP_Tx;
-	http_SetResp(sp->wrk->resp, "HTTP/1.1", "304", "Not Modified");
+	http_SetResp(sp->wrk->resp, "HTTP/1.1", 304, "Not Modified");
 	TIM_format(sp->t_req, lm);
 	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", lm);
 	http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Via: 1.1 varnish");
@@ -181,7 +181,7 @@
 	http_Unset(sp->wrk->resp, H_Content_Length);
 	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
 	    "Content-Length: %u", 1 + high - low);
-	http_SetResp(sp->wrk->resp, "HTTP/1.1", "206", "Partial Content");
+	http_SetResp(sp->wrk->resp, "HTTP/1.1", 206, "Partial Content");
 
 
 	*plow = low;

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-10-01 08:29:36 UTC (rev 5375)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-10-01 08:50:43 UTC (rev 5376)
@@ -298,15 +298,8 @@
 void
 VRT_l_obj_status(const struct sess *sp, int num)
 {
-	char *p;
 
 	assert(num >= 100 && num <= 999);
-	p = WS_Alloc(sp->obj->http->ws, 4);
-	if (p == NULL)
-		WSP(sp, SLT_LostHeader, "%s", "obj.status");
-	else
-		sprintf(p, "%d", num);
-	http_SetH(sp->obj->http, HTTP_HDR_STATUS, p);
 	sp->obj->http->status = num;
 }
 
@@ -367,38 +360,27 @@
 int
 VRT_r_obj_status(const struct sess *sp)
 {
+
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
-	/* XXX: use http_GetStatus() */
-	if (sp->obj->http->status)
-		return (sp->obj->http->status);
-	AN(sp->obj->http->hd[HTTP_HDR_STATUS].b);
-	return (atoi(sp->obj->http->hd[HTTP_HDR_STATUS].b));
+	return (sp->obj->http->status);
 }
 
 void
 VRT_l_resp_status(const struct sess *sp, int num)
 {
-	char *p;
 
 	assert(num >= 100 && num <= 999);
-	p = WS_Alloc(sp->wrk->ws, 4);
-	if (p == NULL)
-		WSP(sp, SLT_LostHeader, "%s", "resp.status");
-	else
-		sprintf(p, "%d", num);
-	http_SetH(sp->wrk->resp, HTTP_HDR_STATUS, p);
 	sp->wrk->resp->status = num;
 }
 
 int
 VRT_r_resp_status(const struct sess *sp)
 {
+
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk->resp, HTTP_MAGIC);
-	if (sp->wrk->resp->status)
-		return (sp->wrk->resp->status);
-	return (atoi(sp->wrk->resp->hd[HTTP_HDR_STATUS].b));
+	return (sp->wrk->resp->status);
 }
 
 /*--------------------------------------------------------------------*/
@@ -484,15 +466,8 @@
 void
 VRT_l_beresp_status(const struct sess *sp, int num)
 {
-	char *p;
 
 	assert(num >= 100 && num <= 999);
-	p = WS_Alloc(sp->wrk->beresp->ws, 4);
-	if (p == NULL)
-		WSP(sp, SLT_LostHeader, "%s", "obj.status");
-	else
-		sprintf(p, "%d", num);
-	http_SetH(sp->wrk->beresp, HTTP_HDR_STATUS, p);
 	sp->wrk->beresp->status = num;
 }
 
@@ -500,11 +475,7 @@
 VRT_r_beresp_status(const struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	/* XXX: use http_GetStatus() */
-	if (sp->wrk->beresp->status)
-		return (sp->wrk->beresp->status);
-	AN(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b);
-	return (atoi(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b));
+	return (sp->wrk->beresp->status);
 }
 
 
@@ -780,7 +751,7 @@
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	sp->hash_ignore_busy = ignore_busy;
+	sp->hash_ignore_busy = ignore_busy ? 1 : 0;
 }
 
 unsigned
@@ -800,7 +771,7 @@
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	sp->hash_always_miss = always_miss;
+	sp->hash_always_miss = always_miss ? 1 : 0;
 }
 
 unsigned




More information about the varnish-commit mailing list