r576 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 31 22:38:46 CEST 2006


Author: phk
Date: 2006-07-31 22:38:46 +0200 (Mon, 31 Jul 2006)
New Revision: 576

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Add a http_SetResp() function for constructing HTTP responses (like 304).

Eliminate the header index from http_SetHeader() which is no unused.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-31 20:27:02 UTC (rev 575)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-31 20:38:46 UTC (rev 576)
@@ -327,9 +327,10 @@
 void http_GetReq(int fd, struct http *to, struct http *fm);
 void http_CopyReq(int fd, struct http *to, struct http *fm);
 void http_CopyResp(int fd, struct http *to, struct http *fm);
+void http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response);
 void http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how);
 void http_PrintfHeader(int fd, struct http *to, const char *fmt, ...);
-void http_SetHeader(int fd, struct http *to, unsigned n, const char *hdr);
+void http_SetHeader(int fd, struct http *to, const char *hdr);
 int http_IsHdr(struct http_hdr *hh, char *hdr);
 void http_Setup(struct http *ht, void *space, unsigned len);
 int http_GetHdr(struct http *hp, const char *hdr, char **ptr);

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-31 20:27:02 UTC (rev 575)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-31 20:38:46 UTC (rev 576)
@@ -580,6 +580,15 @@
 	http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, SLT_Response);
 }
 
+void
+http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response)
+{
+	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+	http_seth(fd, to, HTTP_HDR_PROTO, SLT_Protocol, proto);
+	http_seth(fd, to, HTTP_HDR_STATUS, SLT_Status, status);
+	http_seth(fd, to, HTTP_HDR_RESPONSE, SLT_Response, response);
+}
+
 static void
 http_copyheader(int fd, struct http *to, struct http *fm, unsigned n)
 {
@@ -620,14 +629,14 @@
 /*--------------------------------------------------------------------*/
 
 void
-http_SetHeader(int fd, struct http *to, unsigned n, const char *hdr)
+http_SetHeader(int fd, struct http *to, const char *hdr)
 {
 
-	if (n == 0)
-		n = to->nhd++;
-	to->hd[n].b = (void*)(uintptr_t)hdr;
-	to->hd[n].e = strchr(hdr, '\0');
-	VSLHT(fd, to, n);
+	to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
+	to->hd[to->nhd].e = strchr(hdr, '\0');
+	assert(to->hd[to->nhd].e != NULL);
+	VSLHT(fd, to, to->nhd);
+	to->nhd++;
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-31 20:27:02 UTC (rev 575)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-31 20:38:46 UTC (rev 576)
@@ -84,16 +84,14 @@
 
 	sp->http->f = sp->http->v;
 
-	http_SetHeader(sp->fd, sp->http, HTTP_HDR_PROTO, "HTTP/1.1");
-	http_SetHeader(sp->fd, sp->http, HTTP_HDR_STATUS, "304");
-	http_SetHeader(sp->fd, sp->http, HTTP_HDR_RESPONSE, "Not Modified");
+	http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
 
 	sp->http->nhd = HTTP_HDR_FIRST;
-	http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
+	http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
 	http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", p);
 	if (sp->doclose != NULL)
-		http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
+		http_SetHeader(sp->fd, sp->http, "Connection: close");
 	WRK_Reset(sp->wrk, &sp->fd);
 	http_Write(sp->wrk, sp->http, 1);
 	if (WRK_Flush(sp->wrk))
@@ -150,9 +148,9 @@
 		http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->fd, sp->http, "Age: %u",
 	    sp->obj->age + sp->t_req - sp->obj->entered);
-	http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
+	http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
 	if (sp->doclose != NULL)
-		http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
+		http_SetHeader(sp->fd, sp->http, "Connection: close");
 	WRK_Reset(sp->wrk, &sp->fd);
 	sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
 	




More information about the varnish-commit mailing list