Browse Source

add missing header_get to repo and build header hash only from lowercase letters now as it seems header identifier should be case insensitive

master
Georg Hopp 14 years ago
parent
commit
1c5d6099f5
  1. 6
      ChangeLog
  2. 46
      src/http/request/header_get.c
  3. 2
      src/http/request_parser.c

6
ChangeLog

@ -1,6 +1,10 @@
2012-02-09 11:32:28 +0100 Georg Hopp
* 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)
2012-02-09 09:34:21 +0100 Georg Hopp 2012-02-09 09:34:21 +0100 Georg Hopp
* access to headers via hash, read body (actually only with content-length header should also look for content-encoding) (HEAD, master)
* access to headers via hash, read body (actually only with content-length header should also look for content-encoding)
2012-02-08 16:51:49 +0100 Georg Hopp 2012-02-08 16:51:49 +0100 Georg Hopp

46
src/http/request/header_get.c

@ -0,0 +1,46 @@
#include <stdlib.h>
#include <ctype.h>
#include "http/request.h"
static
inline
unsigned long
sdbm(const unsigned char * str)
{
unsigned long hash = 0;
int c;
while ((c = tolower(*str++)))
hash = c + (hash << 6) + (hash << 16) - hash;
return hash;
}
static
inline
int
comp (const void * _a, const void * _b)
{
unsigned long a = *(unsigned long *)_a;
const struct HttpRequestHeader * b = _b;
return (a < b->hash)? -1 : (a > b->hash)? 1 : 0;
}
char *
httpRequestHeaderGet(HttpRequest this, const char * name)
{
unsigned long hash = sdbm((unsigned char *)name);
struct HttpRequestHeader * header;
header = bsearch(
&hash,
this->header,
this->nheader,
sizeof(struct HttpRequestHeader),
comp);
return (NULL != header)? header->value : NULL;
}
// vim: set ts=4 sw=4:

2
src/http/request_parser.c

@ -150,7 +150,7 @@ sdbm(unsigned char * str)
unsigned long hash = 0; unsigned long hash = 0;
int c; int c;
while ((c = *str++))
while ((c = tolower(*str++)))
hash = c + (hash << 6) + (hash << 16) - hash; hash = c + (hash << 6) + (hash << 16) - hash;
return hash; return hash;

Loading…
Cancel
Save