Commit b5824163 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rewrite http_Merge() to pull from OA_HEADERS

parent 9b35b6f7
......@@ -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);
......
......@@ -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
......
......@@ -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;
}
}
/*--------------------------------------------------------------------*/
......@@ -826,37 +856,6 @@ http_FilterReq(struct http *to, const struct http *fm, unsigned how)
http_filterfields(to, fm, 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.
......
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