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