r5716 - trunk/varnish-cache/bin/varnishd
phk at varnish-cache.org
phk at varnish-cache.org
Wed Jan 12 12:38:53 CET 2011
Author: phk
Date: 2011-01-12 12:38:53 +0100 (Wed, 12 Jan 2011)
New Revision: 5716
Added:
trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_esi.c
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Gzip support for ESI is turning into a new implementation of ESI, so
bite the bullet and do so.
Add an OLD_ESI macro which defines which implementation we use and
set it by default.
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2011-01-12 11:38:53 UTC (rev 5716)
@@ -25,6 +25,7 @@
cache_dir_random.c \
cache_dir_dns.c \
cache_dir_round_robin.c \
+ cache_esi_parse.c \
cache_esi.c \
cache_expire.c \
cache_fetch.c \
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2011-01-12 11:38:53 UTC (rev 5716)
@@ -35,6 +35,8 @@
*/
#define VARNISH_CACHE_CHILD 1
+#define OLD_ESI
+
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/socket.h>
@@ -225,6 +227,7 @@
extern struct vfp vfp_gunzip;
extern struct vfp vfp_gzip;
+extern struct vfp vfp_esi;
/*--------------------------------------------------------------------*/
@@ -284,6 +287,9 @@
unsigned do_gzip;
unsigned do_gunzip;
+ /* ESI stuff */
+ struct vep_state *vep;
+
/* Timeouts */
double connect_timeout;
double first_byte_timeout;
@@ -436,7 +442,11 @@
VTAILQ_HEAD(, storage) store;
+#ifdef OLD_ESI
struct esidata *esidata;
+#else
+ struct storage *esidata;
+#endif
double last_use;
@@ -795,11 +805,13 @@
char *VRT_String(struct ws *ws, const char *h, const char *p, va_list ap);
char *VRT_StringList(char *d, unsigned dl, const char *p, va_list ap);
+#ifdef OLD_ESI
/* cache_vrt_esi.c */
void ESI_Deliver(struct sess *);
void ESI_Destroy(struct object *);
void ESI_Parse(struct sess *);
+#endif /* OLD_ESI */
/* cache_vrt_vmod.c */
void VMOD_Init(void);
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2011-01-12 11:38:53 UTC (rev 5716)
@@ -587,14 +587,16 @@
AZ(sp->wrk->vfp);
/* XXX: precedence, also: do_esi */
-
+#ifndef OLD_ESI
+ if (sp->wrk->do_esi) {
+ sp->wrk->vfp = &vfp_esi;
+ } else
+#endif
if (sp->wrk->do_gunzip &&
http_HdrIs(sp->wrk->beresp, H_Content_Encoding, "gzip")) {
http_Unset(sp->wrk->beresp, H_Content_Encoding);
sp->wrk->vfp = &vfp_gunzip;
- }
-
- if (sp->wrk->do_gzip &&
+ } else if (sp->wrk->do_gzip &&
!http_HdrIs(sp->wrk->beresp, H_Content_Encoding, "gzip")) {
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->beresp,
"Content-Encoding: %s", "gzip");
@@ -675,8 +677,10 @@
return (0);
}
+#ifdef OLD_ESI
if (sp->wrk->do_esi)
ESI_Parse(sp);
+#endif
switch (sp->handling) {
case VCL_RET_RESTART:
Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2011-01-12 11:38:53 UTC (rev 5716)
@@ -38,6 +38,7 @@
* hanging, esi:include
*/
+
#include "config.h"
#include "svnid.h"
@@ -56,6 +57,8 @@
#include "cache.h"
#include "stevedore.h"
+#ifdef OLD_ESI
+
/*--------------------------------------------------------------------*/
struct esi_bit {
@@ -959,3 +962,5 @@
CHECK_OBJ_NOTNULL(ed, ESIDATA_MAGIC);
STV_free(ed->storage);
}
+
+#endif /* OLD_ESI */
Added: trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi_parse.c (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_esi_parse.c 2011-01-12 11:38:53 UTC (rev 5716)
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef OLD_ESI
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id")
+
+#include "cache.h"
+#include "stevedore.h"
+
+struct vep_state {
+ unsigned magic;
+#define VEP_MAGIC 0x55cb9b82
+ vfp_bytes_f *bytes;
+ struct vsb *vsb;
+};
+
+/*---------------------------------------------------------------------
+ * We receive a ungzip'ed object, and want to store it ungzip'ed.
+ */
+
+static int __match_proto__()
+vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
+{
+ struct vep_state *vep;
+ ssize_t l, w;
+ struct storage *st;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ vep = sp->wrk->vep;
+ CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
+
+ while (bytes > 0) {
+ if (sp->wrk->storage == NULL) {
+ l = params->fetch_chunksize * 1024LL;
+ sp->wrk->storage = STV_alloc(sp, l);
+ }
+ if (sp->wrk->storage == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ st = sp->wrk->storage;
+ l = st->space - st->len;
+ if (l > bytes)
+ l = bytes;
+ w = HTC_Read(htc, st->ptr + st->len, l);
+ if (w <= 0)
+ return (w);
+ st->len += w;
+ sp->obj->len += w;
+ if (st->len == st->space) {
+ VTAILQ_INSERT_TAIL(&sp->obj->store,
+ sp->wrk->storage, list);
+ sp->wrk->storage = NULL;
+ st = NULL;
+ }
+ bytes -= w;
+ }
+ return (1);
+}
+
+/*---------------------------------------------------------------------*/
+
+static void __match_proto__()
+vfp_esi_begin(struct sess *sp, size_t estimate)
+{
+ struct vep_state *vep;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ AZ(sp->wrk->vep);
+ vep = (void*)WS_Alloc(sp->wrk->ws, sizeof *vep);
+ AN(vep);
+
+ memset(vep, 0, sizeof *vep);
+ vep->magic = VEP_MAGIC;
+ vep->bytes = vfp_esi_bytes_uu;
+ vep->vsb = vsb_newauto();
+ AN(vep->vsb);
+
+ sp->wrk->vep = vep;
+ (void)estimate;
+}
+
+static int __match_proto__()
+vfp_esi_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
+{
+ struct vep_state *vep;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ vep = sp->wrk->vep;
+ CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
+ AN(vep->bytes);
+ return (vep->bytes(sp, htc, bytes));
+}
+
+static int __match_proto__()
+vfp_esi_end(struct sess *sp)
+{
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ return (-1);
+}
+
+struct vfp vfp_esi = {
+ .begin = vfp_esi_begin,
+ .bytes = vfp_esi_bytes,
+ .end = vfp_esi_end,
+};
+
+#endif /* OLD_ESI */
Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2011-01-12 11:38:53 UTC (rev 5716)
@@ -693,8 +693,15 @@
DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u",
o->xid, WS_Free(o->ws_o));
+#ifdef OLD_ESI
if (o->esidata != NULL)
ESI_Destroy(o);
+#else
+ if (o->esidata != NULL) {
+ STV_free(o->esidata);
+ o->esidata = NULL;
+ }
+#endif
if (oc != NULL)
oc_freeobj(oc);
w->stats.n_object--;
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2011-01-11 13:12:34 UTC (rev 5715)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2011-01-12 11:38:53 UTC (rev 5716)
@@ -386,8 +386,10 @@
/* This was a HEAD request */
} else if (sp->obj->len == 0) {
/* Nothing to do here */
+#ifdef OLD_ESI
} else if (sp->wrk->res_mode & RES_ESI) {
ESI_Deliver(sp);
+#endif
} else if (sp->wrk->res_mode & RES_GUNZIP) {
res_WriteGunzipObj(sp, lenbuf);
} else {
More information about the varnish-commit
mailing list