Improve llcache header processing

By skipping empty headers and correctly dealing with whitespace around
header names we store fewer entries with better adherance to allowed
values in http responses.
This commit is contained in:
Vincent Sanders 2014-03-08 14:25:15 +00:00
parent 25ce52ee64
commit da0b969f25
1 changed files with 22 additions and 7 deletions

View File

@ -382,11 +382,25 @@ static nserror llcache_fetch_split_header(const uint8_t *data, size_t len,
char *n, *v;
const uint8_t *colon;
/* Strip leading whitespace from name */
while (data[0] == ' ' || data[0] == '\t' ||
data[0] == '\r' || data[0] == '\n') {
data++;
}
/* Find colon */
colon = (const uint8_t *) strchr((const char *) data, ':');
if (colon == NULL) {
/* Failed, assume a key with no value */
n = strdup((const char *) data);
colon = data + strlen((const char *)data);
/* Strip trailing whitespace from name */
while ((colon > data) &&
(colon[-1] == ' ' || colon[-1] == '\t' ||
colon[-1] == '\r' || colon[-1] == '\n')) {
colon--;
}
n = strndup((const char *) data, colon - data);
if (n == NULL)
return NSERROR_NOMEM;
@ -398,12 +412,6 @@ static nserror llcache_fetch_split_header(const uint8_t *data, size_t len,
} else {
/* Split header into name & value */
/* Strip leading whitespace from name */
while (data[0] == ' ' || data[0] == '\t' ||
data[0] == '\r' || data[0] == '\n') {
data++;
}
/* Strip trailing whitespace from name */
while (colon > data && (colon[-1] == ' ' ||
colon[-1] == '\t' || colon[-1] == '\r' ||
@ -613,6 +621,13 @@ static nserror llcache_fetch_process_header(llcache_object *object,
return error;
}
/* deal with empty header */
if (name[0] == 0) {
free(name);
free(value);
return NSERROR_OK;
}
/* Append header data to the object's headers array */
temp = realloc(object->headers, (object->num_headers + 1) *
sizeof(llcache_header));