[master] b582416 Rewrite http_Merge() to pull from OA_HEADERS
Poul-Henning Kamp
phk at FreeBSD.org
Tue Aug 12 23:44:13 CEST 2014
commit b58241634cd84c8314e5face68bd9bb0da091be7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Aug 12 21:43:55 2014 +0000
Rewrite http_Merge() to pull from OA_HEADERS
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 54af650..0b6ebd3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -185,7 +185,6 @@ struct http {
txt *hd;
unsigned char *hdf;
#define HDF_FILTER (1 << 0) /* Filtered by Connection */
-#define HDF_MARKER (1 << 1) /* Marker bit */
/* NB: ->nhd and below zeroed/initialized by http_Teardown */
uint16_t nhd; /* Next free hd */
@@ -982,7 +981,7 @@ void http_MarkHeader(const struct http *, const char *hdr, unsigned hdrlen,
uint8_t flag);
void http_CollectHdr(struct http *hp, const char *hdr);
void http_VSL_log(const struct http *hp);
-void http_Merge(const struct http *fm, struct http *to);
+void HTTP_Merge(struct objcore *, struct dstat *, struct http *to);
const char *HTTP_GetHdrPack(struct objcore *, struct dstat *,
const char *hdr);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 895de56..03b4772 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -359,7 +359,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
http_Unset(bo->beresp, H_Content_Encoding);
RFC2616_Weaken_Etag(bo->beresp);
}
- http_Merge(bo->ims_obj->http, bo->beresp);
+ HTTP_Merge(bo->ims_oc, bo->stats, bo->beresp);
assert(http_IsStatus(bo->beresp, 200));
do_ims = 1;
} else
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index db4123b..f6a7f39 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -726,7 +726,7 @@ HTTP_Decode(struct http *to, uint8_t *fm)
const char *
HTTP_GetHdrPack(struct objcore *oc, struct dstat *ds, const char *hdr)
{
- char *ptr;
+ const char *ptr;
unsigned l;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -746,14 +746,10 @@ HTTP_GetHdrPack(struct objcore *oc, struct dstat *ds, const char *hdr)
/* Skip PROTO, STATUS and REASON */
ptr = strchr(ptr, '\0') + 1;
- VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
ptr = strchr(ptr, '\0') + 1;
- VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
ptr = strchr(ptr, '\0') + 1;
- VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
while (*ptr != '\0') {
- VSL(SLT_Debug, 0, "%d <%s> %u <%s>", __LINE__, ptr, l, hdr);
if (!strncasecmp(ptr, hdr, l)) {
ptr += l;
assert (vct_issp(*ptr));
@@ -762,12 +758,46 @@ HTTP_GetHdrPack(struct objcore *oc, struct dstat *ds, const char *hdr)
return (ptr);
}
ptr = strchr(ptr, '\0') + 1;
- VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
}
return (NULL);
}
+/*--------------------------------------------------------------------
+ * Merge any headers in the oc->OA_HEADER into the struct http if they
+ * are not there already.
+ */
+void
+HTTP_Merge(struct objcore *oc, struct dstat *ds, struct http *to)
+{
+ const char *ptr;
+ unsigned u;
+ const char *p;
+
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ AN(ds);
+
+ ptr = ObjGetattr(oc, ds, OA_HEADERS, NULL);
+ AN(ptr);
+
+ to->status = vbe16dec(ptr + 2);
+ ptr += 4;
+
+ for (u = 0; u < HTTP_HDR_FIRST; u++) {
+ if (u == HTTP_HDR_METHOD || u == HTTP_HDR_URL)
+ continue;
+ http_SetH(to, u, ptr);
+ ptr = strchr(ptr, '\0') + 1;
+ }
+ while (*ptr != '\0') {
+ p = strchr(ptr, ':');
+ AN(p);
+ if (!http_findhdr(to, p - ptr, ptr))
+ http_SetHeader(to, ptr);
+ ptr = strchr(ptr, '\0') + 1;
+ }
+}
/*--------------------------------------------------------------------*/
@@ -827,37 +857,6 @@ http_FilterReq(struct http *to, const struct http *fm, unsigned how)
}
/*--------------------------------------------------------------------
- * Merge two HTTP headers the "wrong" way. Used by backend IMS to
- * merge in the headers of the validated object with the headers of
- * the 304 response.
- */
-
-void
-http_Merge(const struct http *fm, struct http *to)
-{
- unsigned u, v;
- const char *p;
-
- to->status = fm->status;
- http_linkh(to, fm, HTTP_HDR_PROTO);
- http_linkh(to, fm, HTTP_HDR_STATUS);
- http_linkh(to, fm, HTTP_HDR_REASON);
-
- for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
- fm->hdf[u] |= HDF_MARKER;
- for (v = HTTP_HDR_FIRST; v < to->nhd; v++) {
- p = strchr(to->hd[v].b, ':');
- AN(p);
- u = http_findhdr(fm, p - to->hd[v].b, to->hd[v].b);
- if (u)
- fm->hdf[u] &= ~HDF_MARKER;
- }
- for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
- if (fm->hdf[u] & HDF_MARKER)
- http_SetHeader(to, fm->hd[u].b);
-}
-
-/*--------------------------------------------------------------------
* This function copies any header fields which reference foreign
* storage into our own WS.
*/
More information about the varnish-commit
mailing list