Commit 1c5d6099f584fc1b510a69e70d9027c64d727c46

Authored by Georg Hopp
1 parent f678adca

add missing header_get to repo and build header hash only from lowercase letters…

… now as it seems header identifier should be case insensitive
  1 +2012-02-09 11:32:28 +0100 Georg Hopp
  2 +
  3 + * add missing header_get to repo and build header hash only from lowercase letters now as it seems header identifier should be case insensitive (HEAD, master)
  4 +
1 5 2012-02-09 09:34:21 +0100 Georg Hopp
2 6
3   - * access to headers via hash, read body (actually only with content-length header should also look for content-encoding) (HEAD, master)
  7 + * access to headers via hash, read body (actually only with content-length header should also look for content-encoding)
4 8
5 9 2012-02-08 16:51:49 +0100 Georg Hopp
6 10
... ...
  1 +#include <stdlib.h>
  2 +#include <ctype.h>
  3 +
  4 +#include "http/request.h"
  5 +
  6 +static
  7 +inline
  8 +unsigned long
  9 +sdbm(const unsigned char * str)
  10 +{
  11 + unsigned long hash = 0;
  12 + int c;
  13 +
  14 + while ((c = tolower(*str++)))
  15 + hash = c + (hash << 6) + (hash << 16) - hash;
  16 +
  17 + return hash;
  18 +}
  19 +
  20 +static
  21 +inline
  22 +int
  23 +comp (const void * _a, const void * _b)
  24 +{
  25 + unsigned long a = *(unsigned long *)_a;
  26 + const struct HttpRequestHeader * b = _b;
  27 + return (a < b->hash)? -1 : (a > b->hash)? 1 : 0;
  28 +}
  29 +
  30 +char *
  31 +httpRequestHeaderGet(HttpRequest this, const char * name)
  32 +{
  33 + unsigned long hash = sdbm((unsigned char *)name);
  34 + struct HttpRequestHeader * header;
  35 +
  36 + header = bsearch(
  37 + &hash,
  38 + this->header,
  39 + this->nheader,
  40 + sizeof(struct HttpRequestHeader),
  41 + comp);
  42 +
  43 + return (NULL != header)? header->value : NULL;
  44 +}
  45 +
  46 +// vim: set ts=4 sw=4:
... ...
... ... @@ -150,7 +150,7 @@ sdbm(unsigned char * str)
150 150 unsigned long hash = 0;
151 151 int c;
152 152
153   - while ((c = *str++))
  153 + while ((c = tolower(*str++)))
154 154 hash = c + (hash << 6) + (hash << 16) - hash;
155 155
156 156 return hash;
... ...
Please register or login to post a comment