summaryrefslogtreecommitdiff
path: root/env.c
blob: 77c90f90e3fcd4ae6e6b2913f9622ebb6a961729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "internal.h"

static char * const
fhp_strings[] = {
  "GET",
  "POST",
  "HEAD",
  "PUT",
  "DELETE",
  "OPTIONS",
  "HTTP/1.0",
  "HTTP/1.1",
  "content-length",
  "content-type",
  "transfer-encoding",
  "gzip",
  "x-gzip",
  "deflate",
  "x-deflate",
  "compress",
  "x-compress",
  "chunked",
  "application/x-www-form-urlencoded",
  "multipart/form-data",
  NULL
};

void
fhp_env_init(fhp_env_t * const env) {
  // calculate hashes for common strings
  for (size_t i = 0; fhp_strings[i]; i++)
    env->hashes[i] = fhp_lc_hash_string(fhp_strings[i]);
}

static fhp_env_t fhp_default_env;

fhp_env_t *
fhp_get_default_env(void) {
  static fhp_env_t *r = NULL;

  // lazy-init default environment
  if (!r) {
    r = &fhp_default_env;
    fhp_env_init(r);
  }

  // return success
  return r;
}