Added some http header helpers

personal/stbuehler/wip
Stefan Bühler 15 years ago
parent 3041e2429d
commit 52c5b05713
  1. 34
      src/http_headers.c
  2. 8
      src/http_headers.h

@ -120,3 +120,37 @@ gboolean http_header_remove(http_headers *headers, const gchar *key, size_t keyl
g_string_free(lokey, TRUE);
return res;
}
http_header* http_header_lookup(http_headers *headers, const gchar *key, size_t keylen) {
GString *lokey;
http_header *h;
lokey = g_string_new_len(key, keylen);
g_string_ascii_down(lokey);
h = (http_header*) g_hash_table_lookup(headers->table, lokey);
g_string_free(lokey, TRUE);
return h;
}
http_header* http_header_lookup_fast(http_headers *headers, const gchar *key, size_t keylen) {
GString lokey;
http_header *h;
/* Fake GString */
lokey.str = (gchar*) key;
lokey.len = lokey.allocated_len = keylen;
h = (http_header*) g_hash_table_lookup(headers->table, &lokey);
return h;
}
gboolean http_header_is(http_headers *headers, const gchar *key, size_t keylen, const gchar *value, size_t valuelen) {
http_header *h = http_header_lookup_fast(headers, key, keylen);
GList *iter;
UNUSED(valuelen);
if (!h) return FALSE;
for (iter = g_queue_peek_head_link(&h->values); NULL != iter; iter = g_list_next(iter)) {
if (0 == strcasecmp( ((GString*)iter->data)->str, value )) return TRUE;
}
return FALSE;
}

@ -33,4 +33,12 @@ LI_API void http_header_insert(http_headers *headers, const gchar *key, size_t k
LI_API void http_header_overwrite(http_headers *headers, const gchar *key, size_t keylen, const gchar *value, size_t valuelen);
LI_API gboolean http_header_remove(http_headers *headers, const gchar *key, size_t keylen);
LI_API http_header* http_header_lookup(http_headers *headers, const gchar *key, size_t keylen);
/** Use lowercase keys! */
LI_API http_header* http_header_lookup_fast(http_headers *headers, const gchar *key, size_t keylen);
/** Use lowercase keys! values are compared case-insensitive */
LI_API gboolean http_header_is(http_headers *headers, const gchar *key, size_t keylen, const gchar *value, size_t valuelen);
#endif

Loading…
Cancel
Save