[experimental-ims] 5c39139 Merge master -> experimental-ims Retaining http_copyheader() in cache_http.c (factored out of master) because IMS uses it to copy from stale_obj to req->obj

Geoff Simmons geoff at varnish-cache.org
Tue Jan 17 14:21:28 CET 2012


commit 5c39139c44eb4243aad50fc72701ca612523bf5e
Merge: b05baa6 4c8f484
Author: Geoff Simmons <geoff at uplex.de>
Date:   Tue Jan 17 14:18:37 2012 +0100

    Merge master -> experimental-ims
    Retaining http_copyheader() in cache_http.c (factored out of master)
    because IMS uses it to copy from stale_obj to req->obj

diff --cc bin/varnishd/cache/cache.h
index 833828d,817b7c7..4917a38
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@@ -800,18 -797,11 +800,17 @@@ void HTTP_Init(void)
  void http_ClrHeader(struct http *to);
  unsigned http_Write(struct worker *w, unsigned vsl_id, const struct http *hp,
      int resp);
- void http_CopyResp(struct http *to, const struct http *fm);
  void http_SetResp(struct http *to, const char *proto, uint16_t status,
      const char *response);
- void http_FilterFields(struct worker *w, unsigned vsl_id, struct http *to,
-     const struct http *fm, unsigned how);
- void http_FilterHeader(const struct sess *sp, unsigned how);
+ void http_FilterReq(const struct sess *sp, unsigned how);
+ void http_FilterResp(const struct sess *sp, const struct http *fm, struct http *to,
+     unsigned how);
 +
 +/* Check if a refresh should be done */
 +void http_CheckRefresh(struct sess *sp);
 +/* Check if we got 304 response */
 +void http_Check304(struct sess *sp, struct busyobj *busyobj);
 +
  void http_PutProtocol(struct worker *w, unsigned vsl_id, const struct http *to,
      const char *protocol);
  void http_PutStatus(struct http *to, uint16_t status);
diff --cc bin/varnishd/cache/cache_center.c
index 3b2e613,a9c233b..c16c42e
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@@ -900,15 -876,10 +900,11 @@@ cnt_fetchbody(struct sess *sp, struct w
  	hp2 = req->obj->http;
  
  	hp2->logtag = HTTP_Obj;
- 	http_CopyResp(hp2, hp);
-         
- 	http_FilterFields(wrk, sp->vsl_id, hp2, hp,
- 	    pass ? HTTPH_R_PASS : HTTPH_A_INS);
- 
+ 	http_FilterResp(sp, hp, hp2, pass ? HTTPH_R_PASS : HTTPH_A_INS);
  	http_CopyHome(wrk, sp->vsl_id, hp2);
  
 -	if (http_GetHdr(hp, H_Last_Modified, &b))
 +	if (http_GetHdr(hp, H_Last_Modified, &b)
 +            || http_GetHdr(req->obj->http, H_Last_Modified, &b))
  		req->obj->last_modified = VTIM_parse(b);
  	else
  		req->obj->last_modified = floor(wrk->busyobj->exp.entered);
diff --cc bin/varnishd/cache/cache_http.c
index 7ea85f2,0b0b926..ceef821
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@@ -917,83 -862,21 +906,100 @@@ http_FilterReq(const struct sess *sp, u
  	    "X-Varnish: %u", sp->req->xid);
  }
  
 +/*-------------------------------------------------------------------
 + * This function checks for sp->freshen_obj.  If present, HSH_Lookup()
 + * found an expired object that qualifies for a refresh check,
 + * so add the appropriate headers.
 + */
 +
 +void
 +http_CheckRefresh(struct sess *sp)
 +{
 +	struct object *freshen_obj;
 +	struct http *obj_hp, *bereq_hp;
 +	char *p;
 +
 +	freshen_obj = sp->stale_obj;
 +	CHECK_OBJ_NOTNULL(freshen_obj, OBJECT_MAGIC);
 +	bereq_hp = sp->wrk->busyobj->bereq;
 +	CHECK_OBJ_NOTNULL(bereq_hp, HTTP_MAGIC);
 +	obj_hp = freshen_obj->http;
 +	CHECK_OBJ_NOTNULL(obj_hp, HTTP_MAGIC);
 +
 +	if(http_GetHdr(obj_hp, H_ETag, &p))
- 		http_PrintfHeader(sp->wrk, sp->fd, bereq_hp, "If-None-Match: %s", p);
++		http_PrintfHeader(sp->wrk, sp->fd, bereq_hp,
++		    "If-None-Match: %s", p);
 +
 +	if(http_GetHdr(obj_hp, H_Last_Modified, &p))
- 		http_PrintfHeader(sp->wrk, sp->fd, bereq_hp, "If-Modified-Since: %s",p);
++		http_PrintfHeader(sp->wrk, sp->fd, bereq_hp,
++		    "If-Modified-Since: %s", p);
 +}
 +
 +/*-------------------------------------------------------------------
 + * Called after fetch and sp->freshen_obj present.  Check
 + * response and handle as needed.
 + */
 +
 +void
 +http_Check304(struct sess *sp, struct busyobj *busyobj)
 +{
 +	struct object *o_stale;
 +	char *p;
 +
 +	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 +	CHECK_OBJ_NOTNULL(busyobj, BUSYOBJ_MAGIC);
 +	o_stale = sp->stale_obj;
 +	CHECK_OBJ_NOTNULL(o_stale, OBJECT_MAGIC);
 +
 +	if (busyobj->beresp->status != 304) {
 +	    /*
 +	     * IMS/INM headers may have been removed in VCL, so only count a
 +	     * non-validating response if they were present in the request.
 +	     */
 +	    if (http_GetHdr(busyobj->bereq, H_If_Modified_Since, &p)
 +		|| http_GetHdr(busyobj->bereq, H_If_None_Match, &p))
 +		sp->wrk->stats.fetch_not_validated++;
 +
 +	    HSH_Deref(sp->wrk, NULL, &sp->stale_obj);
 +	    AZ(sp->stale_obj);
 +	    return;
 +	}
 +
 +	/* 
 +	 * Copy headers we need from the stale object into the 304 response
 +	 */
 +	http_FilterMissingFields(sp->wrk, sp->fd, busyobj->beresp,
 +	    o_stale->http);
 +
 +	http_SetResp(busyobj->beresp, "HTTP/1.1", 200, "Ok Not Modified");
 +	http_SetH(busyobj->beresp, HTTP_HDR_REQ, "GET");
- 	http_copyh(busyobj->beresp, busyobj->bereq, HTTP_HDR_URL);
++	http_linkh(busyobj->beresp, busyobj->bereq, HTTP_HDR_URL);
 +
 +	/*
 +	 * XXX: Are we copying all the necessary fields from stale_obj?
 +	 *	Should we copy o_stale->hits into o->hits?
 +	 *      What about do_esi and do_g(un)zip?
 +	 */
 +	busyobj->is_gzip = o_stale->gziped;
 +
 +        AZ(o_stale->objcore->flags & OC_F_BUSY);
 +}
 +
+ /*--------------------------------------------------------------------*/
+ 
+ void
+ http_FilterResp(const struct sess *sp, const struct http *fm, struct http *to,
+     unsigned how)
+ {
+ 
+ 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
+ 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ 	http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
+ 	to->status = fm->status;
+ 	http_linkh(to, fm, HTTP_HDR_RESPONSE);
+ 	http_filterfields(sp->wrk, sp->vsl_id, to, fm, how);
+ }
+ 
  /*--------------------------------------------------------------------
   * This function copies any header fields which reference foreign
   * storage into our own WS.



More information about the varnish-commit mailing list