summaryrefslogtreecommitdiff
path: root/content/llcache.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-03-08 14:25:15 +0000
committerVincent Sanders <vince@kyllikki.org>2014-03-09 16:22:28 +0000
commitda0b969f2514df4e6d4febf78c54c8b4c34dcb9a (patch)
tree415b1db8e59a30f3ecc5f3985274b3ddacfe98f4 /content/llcache.c
parent25ce52ee64126caac0550d7086abb79b10e1a951 (diff)
downloadnetsurf-da0b969f2514df4e6d4febf78c54c8b4c34dcb9a.tar.gz
netsurf-da0b969f2514df4e6d4febf78c54c8b4c34dcb9a.tar.bz2
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.
Diffstat (limited to 'content/llcache.c')
-rw-r--r--content/llcache.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/content/llcache.c b/content/llcache.c
index 7d6e6b64d..112a7fab9 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -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));