http_response: implement httpdate in C
[unicorn.git] / ext / unicorn_http / global_variables.h
blobcdbc42d3bb31d50252506fcd5bd3f9456d449210
1 #ifndef global_variables_h
2 #define global_variables_h
3 static VALUE eHttpParserError;
5 static VALUE g_rack_url_scheme;
6 static VALUE g_request_method;
7 static VALUE g_request_uri;
8 static VALUE g_fragment;
9 static VALUE g_query_string;
10 static VALUE g_http_version;
11 static VALUE g_request_path;
12 static VALUE g_path_info;
13 static VALUE g_server_name;
14 static VALUE g_server_port;
15 static VALUE g_server_protocol;
16 static VALUE g_http_host;
17 static VALUE g_http_x_forwarded_proto;
18 static VALUE g_http_x_forwarded_ssl;
19 static VALUE g_http_transfer_encoding;
20 static VALUE g_content_length;
21 static VALUE g_http_trailer;
22 static VALUE g_http_connection;
23 static VALUE g_port_80;
24 static VALUE g_port_443;
25 static VALUE g_localhost;
26 static VALUE g_http;
27 static VALUE g_https;
28 static VALUE g_http_09;
29 static VALUE g_http_10;
30 static VALUE g_http_11;
32 /** Defines common length and error messages for input length validation. */
33 #define DEF_MAX_LENGTH(N, length) \
34 static const size_t MAX_##N##_LENGTH = length; \
35 static const char * const MAX_##N##_LENGTH_ERR = \
36 "HTTP element " # N " is longer than the " # length " allowed length."
38 NORETURN(static void parser_error(const char *));
40 /**
41 * Validates the max length of given input and throws an HttpParserError
42 * exception if over.
44 #define VALIDATE_MAX_LENGTH(len, N) do { \
45 if (len > MAX_##N##_LENGTH) \
46 parser_error(MAX_##N##_LENGTH_ERR); \
47 } while (0)
49 /** Defines global strings in the init method. */
50 #define DEF_GLOBAL(N, val) do { \
51 g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
52 rb_global_variable(&g_##N); \
53 } while (0)
55 /* Defines the maximum allowed lengths for various input elements.*/
56 DEF_MAX_LENGTH(FIELD_NAME, 256);
57 DEF_MAX_LENGTH(FIELD_VALUE, 80 * 1024);
58 DEF_MAX_LENGTH(REQUEST_URI, 1024 * 12);
59 DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewhere or not */
60 DEF_MAX_LENGTH(REQUEST_PATH, 1024);
61 DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10));
62 DEF_MAX_LENGTH(HEADER, (1024 * (80 + 32)));
64 static void init_globals(void)
66 DEF_GLOBAL(rack_url_scheme, "rack.url_scheme");
67 DEF_GLOBAL(request_method, "REQUEST_METHOD");
68 DEF_GLOBAL(request_uri, "REQUEST_URI");
69 DEF_GLOBAL(fragment, "FRAGMENT");
70 DEF_GLOBAL(query_string, "QUERY_STRING");
71 DEF_GLOBAL(http_version, "HTTP_VERSION");
72 DEF_GLOBAL(request_path, "REQUEST_PATH");
73 DEF_GLOBAL(path_info, "PATH_INFO");
74 DEF_GLOBAL(server_name, "SERVER_NAME");
75 DEF_GLOBAL(server_port, "SERVER_PORT");
76 DEF_GLOBAL(server_protocol, "SERVER_PROTOCOL");
77 DEF_GLOBAL(http_x_forwarded_proto, "HTTP_X_FORWARDED_PROTO");
78 DEF_GLOBAL(http_x_forwarded_ssl, "HTTP_X_FORWARDED_SSL");
79 DEF_GLOBAL(port_80, "80");
80 DEF_GLOBAL(port_443, "443");
81 DEF_GLOBAL(localhost, "localhost");
82 DEF_GLOBAL(http, "http");
83 DEF_GLOBAL(https, "https");
84 DEF_GLOBAL(http_11, "HTTP/1.1");
85 DEF_GLOBAL(http_10, "HTTP/1.0");
86 DEF_GLOBAL(http_09, "HTTP/0.9");
89 #undef DEF_GLOBAL
91 #endif /* global_variables_h */