Commit 017ec218 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Martin Blix Grydeland

Pack the HdrPack iterator into a function so other code than HTTP_GetHdrPack()

can also use it.

Patch by:	martin
Some rework by:	phk
parent 6385b5e7
...@@ -831,8 +831,10 @@ void http_CollectHdr(struct http *hp, const char *hdr); ...@@ -831,8 +831,10 @@ void http_CollectHdr(struct http *hp, const char *hdr);
void http_VSL_log(const struct http *hp); void http_VSL_log(const struct http *hp);
void HTTP_Merge(struct worker *, struct objcore *, struct http *to); void HTTP_Merge(struct worker *, struct objcore *, struct http *to);
uint16_t HTTP_GetStatusPack(struct worker *, struct objcore *oc); uint16_t HTTP_GetStatusPack(struct worker *, struct objcore *oc);
const char *HTTP_GetHdrPack(struct worker *, struct objcore *, int HTTP_IterHdrPack(struct worker *, struct objcore *, const char **);
const char *hdr); #define HTTP_FOREACH_PACK(wrk, oc, ptr) \
for ((ptr) = NULL; HTTP_IterHdrPack(wrk, oc, &(ptr));)
const char *HTTP_GetHdrPack(struct worker *, struct objcore *, const char *hdr);
enum sess_close http_DoConnection(struct http *hp); enum sess_close http_DoConnection(struct http *hp);
/* cache_http1_proto.c */ /* cache_http1_proto.c */
......
...@@ -806,6 +806,11 @@ http_EstimateWS(const struct http *fm, unsigned how) ...@@ -806,6 +806,11 @@ http_EstimateWS(const struct http *fm, unsigned how)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Encode http struct as byte string. * Encode http struct as byte string.
*
* XXX: We could save considerable special-casing below by encoding also
* XXX: H__Status, H__Reason and H__Proto into the string, but it would
* XXX: add 26-30 bytes to all encoded objects to save a little code.
* XXX: It could possibly be a good idea for later HTTP versions.
*/ */
void void
...@@ -895,6 +900,32 @@ HTTP_GetStatusPack(struct worker *wrk, struct objcore *oc) ...@@ -895,6 +900,32 @@ HTTP_GetStatusPack(struct worker *wrk, struct objcore *oc)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* Get the first packed header */
int
HTTP_IterHdrPack(struct worker *wrk, struct objcore *oc, const char **p)
{
const char *ptr;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AN(p);
if (*p == NULL) {
ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
AN(ptr);
ptr += 4; /* Skip nhd and status */
ptr = strchr(ptr, '\0') + 1; /* Skip :proto: */
ptr = strchr(ptr, '\0') + 1; /* Skip :status: */
ptr = strchr(ptr, '\0') + 1; /* Skip :reason: */
*p = ptr;
} else {
*p = strchr(*p, '\0') + 1; /* Skip to next header */
}
if (**p == '\0')
return (0);
return (1);
}
const char * const char *
HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr) HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
{ {
...@@ -911,33 +942,32 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr) ...@@ -911,33 +942,32 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
assert(hdr[l] == ':'); assert(hdr[l] == ':');
hdr++; hdr++;
ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL); if (hdr[0] == ':') {
AN(ptr); /* Special cases */
ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
AN(ptr);
ptr += 4; /* Skip nhd and status */
/* Skip nhd and status */ if (!strcmp(hdr, ":proto:"))
ptr += 4; return (ptr);
VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr); ptr = strchr(ptr, '\0') + 1;
if (!strcmp(hdr, ":status:"))
/* Skip PROTO, STATUS and REASON */ return (ptr);
if (!strcmp(hdr, ":proto:")) ptr = strchr(ptr, '\0') + 1;
return (ptr); if (!strcmp(hdr, ":reason:"))
ptr = strchr(ptr, '\0') + 1; return (ptr);
if (!strcmp(hdr, ":status:")) WRONG("Unknown magic packed header");
return (ptr); }
ptr = strchr(ptr, '\0') + 1;
if (!strcmp(hdr, ":reason:"))
return (ptr);
ptr = strchr(ptr, '\0') + 1;
while (*ptr != '\0') { HTTP_FOREACH_PACK(wrk, oc, ptr) {
if (!strncasecmp(ptr, hdr, l)) { if (!strncasecmp(ptr, hdr, l)) {
ptr += l; ptr += l;
while (vct_islws(*ptr)) while (vct_islws(*ptr))
ptr++; ptr++;
return (ptr); return (ptr);
} }
ptr = strchr(ptr, '\0') + 1;
} }
return (NULL); return (NULL);
} }
......
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