r303 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jul 4 22:00:27 CEST 2006


Author: phk
Date: 2006-07-04 22:00:27 +0200 (Tue, 04 Jul 2006)
New Revision: 303

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_pass.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_shmlog.c
Log:
Fix HEAD requests:

Make modes to http_BuildSbuf descriptive enums.
Send GET to backend also for HEAD requests.
Don't return body for HEAD requests.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-04 20:00:27 UTC (rev 303)
@@ -178,7 +178,13 @@
 int http_GetURL(struct http *hp, char **b);
 void http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *func, void *arg);
 void http_Dissect(struct http *sp, int fd, int rr);
-void http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp);
+enum http_build {
+	Build_Pipe,
+	Build_Pass,
+	Build_Fetch,
+	Build_Reply,
+};
+void http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp);
 
 /* cache_main.c */
 extern pthread_mutex_t sessmtx;

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -89,18 +89,22 @@
 {
 	struct storage *st;
 	unsigned u = 0;
+	char *r;
 
 	if (l == 0)
 		l = strlen(b);
 	vca_write(sp, b, l);
-	TAILQ_FOREACH(st, &sp->obj->store, list) {
-		u += st->len;
-		if (st->stevedore->send != NULL)
-			st->stevedore->send(st, sp);
-		else
-			vca_write(sp, st->ptr, st->len);
+	assert(http_GetReq(sp->http, &r));
+	if (!strcmp(r, "GET")) {
+		TAILQ_FOREACH(st, &sp->obj->store, list) {
+			u += st->len;
+			if (st->stevedore->send != NULL)
+				st->stevedore->send(st, sp);
+			else
+				vca_write(sp, st->ptr, st->len);
+		}
+		assert(u == sp->obj->len);
 	}
-	assert(u == sp->obj->len);
 	vca_flush(sp);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -249,7 +249,7 @@
 	VSL(SLT_Backend, sp->fd, "%d %s", fd, sp->backend->vcl_name);
 
 	hp = http_New();
-	http_BuildSbuf(fd, 1, w->sb, sp->http);
+	http_BuildSbuf(fd, Build_Fetch, w->sb, sp->http);
 	i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
 	assert(i == sbuf_len(w->sb));
 	time(&sp->t_req);
@@ -272,7 +272,7 @@
 	if (sp->obj->cacheable)
 		EXP_Insert(sp->obj);
 
-	http_BuildSbuf(sp->fd, 3, w->sb, hp);
+	http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp);
 	if (body) {
 		if (http_GetHdr(hp, "Content-Length", &b))
 			cls = fetch_straight(w, sp, fd, hp, b);

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -415,39 +415,52 @@
 /*--------------------------------------------------------------------*/
 
 void
-http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp)
+http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp)
 {
-	unsigned u;
+	unsigned u, sup;
 
 	sbuf_clear(sb);
 	assert(sb != NULL);
-	if (resp == 2 || resp == 3) {
+	switch (mode) {
+	case Build_Reply:
 		sbuf_cat(sb, hp->proto);
 		sbuf_cat(sb, " ");
 		sbuf_cat(sb, hp->status);
 		sbuf_cat(sb, " ");
 		sbuf_cat(sb, hp->response);
-	} else if (resp == 1) {
+		sup = 2;
+		break;
+	case Build_Pipe:
+	case Build_Pass:
 		sbuf_cat(sb, hp->req);
 		sbuf_cat(sb, " ");
 		sbuf_cat(sb, hp->url);
 		sbuf_cat(sb, " ");
 		sbuf_cat(sb, hp->proto);
-	} else {
-		printf("resp = %d\n", resp);
-		assert(resp == 1 || resp == 2);
+		sup = 2;
+		break;
+	case Build_Fetch:
+		sbuf_cat(sb, "GET ");
+		sbuf_cat(sb, hp->url);
+		sbuf_cat(sb, " ");
+		sbuf_cat(sb, hp->proto);
+		sup = 1;
+		break;
+	default:
+		printf("mode = %d\n", mode);
+		assert(mode == 1 || mode == 2);
 	}
 	sbuf_cat(sb, "\r\n");
 
 	for (u = 0; u < hp->nhdr; u++) {
-		if (http_supress(hp->hdr[u], resp))
+		if (http_supress(hp->hdr[u], sup))
 			continue;
 		if (1)
 			VSL(SLT_BldHdr, fd, "%s", hp->hdr[u]);
 		sbuf_cat(sb, hp->hdr[u]);
 		sbuf_cat(sb, "\r\n");
 	}
-	if (resp != 3) {
+	if (mode != Build_Reply) {
 		sbuf_cat(sb, "\r\n");
 		sbuf_finish(sb);
 	}

Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -160,7 +160,7 @@
 	fd = VBE_GetFd(sp->backend, &fd_token, sp->xid);
 	assert(fd != -1);
 
-	http_BuildSbuf(fd, 1, w->sb, sp->http);
+	http_BuildSbuf(fd, Build_Pass, w->sb, sp->http);
 	i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
 	assert(i == sbuf_len(w->sb));
 

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -51,7 +51,7 @@
 	fd = VBE_GetFd(sp->backend, &fd_token, sp->xid);
 	assert(fd != -1);
 
-	http_BuildSbuf(fd, 0, w->sb, sp->http);	/* XXX: 0 ?? */
+	http_BuildSbuf(fd, Build_Pipe, w->sb, sp->http);	/* XXX: 0 ?? */
 	i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
 	assert(i == sbuf_len(w->sb));
 	assert(__LINE__ == 0);

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -160,6 +160,7 @@
 
 	AZ(pthread_cond_init(&shdcnd, NULL));
 
+	VSL(SLT_Debug, 0, "Starting %u worker threads", heritage.wthread_min);
 	for (i = 0; i < heritage.wthread_min; i++) {
 		AZ(pthread_create(&tp, NULL, CacheWorker, NULL));
 		AZ(pthread_detach(tp));

Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.c	2006-07-04 19:36:00 UTC (rev 302)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c	2006-07-04 20:00:27 UTC (rev 303)
@@ -151,7 +151,6 @@
 	struct shmloghead slh;
 	int i;
 
-	unlink(fn);
 	heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
 	if (heritage.vsl_fd < 0) {
 		fprintf(stderr, "Could not open %s: %s\n",




More information about the varnish-commit mailing list