Commit 4ee1b911 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Wrap the gzip/changed_gzip flags into a more general object flag

mechanism.
parent ab53b55f
......@@ -553,6 +553,12 @@ enum obj_attr {
#undef OBJ_ATTR
};
enum obj_flags {
#define OBJ_FLAG(U, l, v) OF_##U = v,
#include "tbl/obj_attr.h"
#undef OBJ_FLAG
};
struct object {
unsigned magic;
#define OBJECT_MAGIC 0x32851d42
......@@ -564,13 +570,12 @@ struct object {
uint8_t *oa_http;
unsigned gziped:1;
unsigned changed_gzip:1;
uint8_t oa_flags[1];
/* Bit positions in the gzip stream */
char oa_gzipbits[24];
/* VCL only variables */
char oa_lastmodified[8];
......@@ -1077,6 +1082,9 @@ int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
int ObjGetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t *);
int ObjGetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t *);
int ObjCheckFlag(struct objcore *oc, struct dstat *ds, enum obj_flags of);
void ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val);
/* cache_panic.c */
void PAN_Init(void);
const char *body_status_2str(enum body_status e);
......
......@@ -516,7 +516,7 @@ ESI_DeliverChild(struct req *req)
obj = ObjGetObj(req->objcore, &req->wrk->stats);
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
if (!obj->gziped) {
if (!ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED)) {
VTAILQ_FOREACH(st, &obj->body->list, list)
ved_pretend_gzip(req, st->ptr, st->len);
return;
......
......@@ -352,7 +352,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
if (bo->ims_obj != NULL && http_IsStatus(bo->beresp, 304)) {
http_Merge(bo->ims_obj->http, bo->beresp,
bo->ims_obj->changed_gzip);
ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP));
assert(http_IsStatus(bo->beresp, 200));
do_ims = 1;
} else
......@@ -482,10 +482,10 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
bo->vfc->body = obj->body;
if (bo->do_gzip || (bo->is_gzip && !bo->do_gunzip))
obj->gziped = 1;
ObjSetFlag(bo->vfc, OF_GZIPED, 1);
if (bo->do_gzip || bo->do_gunzip)
obj->changed_gzip = 1;
ObjSetFlag(bo->vfc, OF_CHGGZIP, 1);
if (bo->htc.body_status != BS_NONE)
V1F_Setup_Fetch(bo);
......@@ -566,7 +566,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
if (bo->ims_obj->changed_gzip) {
if (ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP)) {
/*
* If we modified the gzip status of the IMS object, that
* must control the C-E header, if any.
......@@ -584,8 +584,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
if (ObjGetattr(bo->ims_oc, bo->stats, OA_ESIDATA, NULL) != NULL)
AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_ESIDATA));
obj->gziped = bo->ims_obj->gziped;
AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_FLAGS));
AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_GZIPBITS));
AZ(WS_Overflowed(bo->ws_o));
......
......@@ -266,7 +266,8 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
req->res_mode |= RES_ESI_CHILD;
}
if (cache_param->http_gzip_support && req->obj->gziped &&
if (cache_param->http_gzip_support &&
ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED) &&
!RFC2616_Req_Gzip(req->http)) {
/*
* We don't know what it uncompresses to
......@@ -344,7 +345,8 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
ESI_DeliverChild(req);
} else if (req->res_mode & RES_GUNZIP ||
(req->res_mode & RES_ESI_CHILD &&
!req->gzip_resp && req->obj->gziped)) {
!req->gzip_resp &&
ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED))) {
VDP_push(req, VDP_gunzip);
req->vgz = VGZ_NewUngzip(req->vsl, "U D -");
AZ(VGZ_WrwInit(req->vgz));
......
......@@ -232,6 +232,9 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
return (NULL);
*len = o->esidata->len;
return (o->esidata->ptr);
case OA_FLAGS:
*len = sizeof o->oa_flags;
return (o->oa_flags);
case OA_GZIPBITS:
*len = sizeof o->oa_gzipbits;
return (o->oa_gzipbits);
......@@ -271,6 +274,9 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
return (NULL);
o->esidata->len = len;
return (o->esidata->ptr);
case OA_FLAGS:
assert(len == sizeof o->oa_flags);
return (o->oa_flags);
case OA_GZIPBITS:
assert(len == sizeof o->oa_gzipbits);
return (o->oa_gzipbits);
......@@ -420,3 +426,29 @@ ObjGetU32(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint32_t *d)
*d = vbe32dec(vp);
return (0);
}
/*--------------------------------------------------------------------
*/
int
ObjCheckFlag(struct objcore *oc, struct dstat *ds, enum obj_flags of)
{
uint8_t *fp;
fp = ObjGetattr(oc, ds, OA_FLAGS, NULL);
AN(fp);
return ((*fp) & of);
}
void
ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val)
{
uint8_t *fp;
fp = ObjSetattr(vc, OA_FLAGS, 1);
AN(fp);
if (val)
(*fp) |= of;
else
(*fp) &= ~of;
}
......@@ -128,7 +128,8 @@ cnt_deliver(struct worker *wrk, struct req *req)
http_SetHeader(req->resp, "Via: 1.1 varnish-v4");
if (cache_param->http_gzip_support && req->obj->gziped &&
if (cache_param->http_gzip_support &&
ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED) &&
!RFC2616_Req_Gzip(req->http))
RFC2616_Weaken_Etag(req->resp);
......
......@@ -30,13 +30,21 @@
/*lint -save -e525 -e539 */
/* upper, lower */
#ifdef OBJ_ATTR
OBJ_ATTR(VXID, vxid)
OBJ_ATTR(EXP, exp)
OBJ_ATTR(VARY, vary)
OBJ_ATTR(HEADERS, headers)
OBJ_ATTR(GZIPFLAGS, gzipflags)
OBJ_ATTR(FLAGS, flags)
OBJ_ATTR(GZIPBITS, gzipbits)
OBJ_ATTR(ESIDATA, esidata)
OBJ_ATTR(LASTMODIFIED, lastmodified)
#endif
#ifdef OBJ_FLAG
/* upper, lower, val */
OBJ_FLAG(GZIPED, gziped, (1<<1))
OBJ_FLAG(CHGGZIP, chggzip, (1<<2))
#endif
/*lint -restore */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment