Skip to content

Commit

Permalink
Have headers_find() strip unnecessary WS.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-davis committed Mar 14, 2010
1 parent e5fc5b7 commit 1383f17
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@ headers_find(struct header_list *headers, const char *key)
TAILQ_FOREACH(line, &h->val, next)
len += line->len;

/* XXX Some of this space is wasted if we trim any leading WS
from value lines */
ret = mem_calloc(1, len + 1);
p = ret;

TAILQ_FOREACH(line, &h->val, next) {
memcpy(p, line->str, line->len);
p += line->len;
len = strspn(line->str, " \t");
/* after the first line, translate leading WS to
a single SP */
if (p != ret)
*p++ = ' ';
memcpy(p, line->str + len, line->len - len);
p += line->len - len;
}

return ret;
Expand Down

0 comments on commit 1383f17

Please sign in to comment.