From 0d89349e78092ad65dfca5b9131218cef0476a37 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 2 Aug 2009 15:25:42 -0700 Subject: http: move global initialization code Just extra noise we don't care about. This also allows us to undef the DEF_GLOBAL macro to avoid polluting the main namespace. --- ext/unicorn_http/global_variables.h | 30 ++++++++++++++++++++++++++++++ ext/unicorn_http/unicorn_http.rl | 25 +------------------------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/ext/unicorn_http/global_variables.h b/ext/unicorn_http/global_variables.h index 1091909..7feef93 100644 --- a/ext/unicorn_http/global_variables.h +++ b/ext/unicorn_http/global_variables.h @@ -54,4 +54,34 @@ DEF_MAX_LENGTH(REQUEST_PATH, 1024); DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10)); DEF_MAX_LENGTH(HEADER, (1024 * (80 + 32))); +void init_globals(void) +{ + mUnicorn = rb_define_module("Unicorn"); + + DEF_GLOBAL(rack_url_scheme, "rack.url_scheme"); + DEF_GLOBAL(request_method, "REQUEST_METHOD"); + DEF_GLOBAL(request_uri, "REQUEST_URI"); + DEF_GLOBAL(fragment, "FRAGMENT"); + DEF_GLOBAL(query_string, "QUERY_STRING"); + DEF_GLOBAL(http_version, "HTTP_VERSION"); + DEF_GLOBAL(request_path, "REQUEST_PATH"); + DEF_GLOBAL(path_info, "PATH_INFO"); + DEF_GLOBAL(server_name, "SERVER_NAME"); + DEF_GLOBAL(server_port, "SERVER_PORT"); + DEF_GLOBAL(server_protocol, "SERVER_PROTOCOL"); + DEF_GLOBAL(server_protocol_value, "HTTP/1.1"); + DEF_GLOBAL(http_x_forwarded_proto, "HTTP_X_FORWARDED_PROTO"); + DEF_GLOBAL(port_80, "80"); + DEF_GLOBAL(port_443, "443"); + DEF_GLOBAL(localhost, "localhost"); + DEF_GLOBAL(http, "http"); + + eHttpParserError = + rb_define_class_under(mUnicorn, "HttpParserError", rb_eIOError); + cHttpParser = rb_define_class_under(mUnicorn, "HttpParser", rb_cObject); + sym_http_body = ID2SYM(rb_intern("http_body")); +} + +#undef DEF_GLOBAL + #endif /* global_variables_h */ diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 8ddf4cc..299d2d9 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -312,34 +312,11 @@ static VALUE HttpParser_execute(VALUE self, VALUE req, VALUE data) void Init_unicorn_http(void) { - mUnicorn = rb_define_module("Unicorn"); - - DEF_GLOBAL(rack_url_scheme, "rack.url_scheme"); - DEF_GLOBAL(request_method, "REQUEST_METHOD"); - DEF_GLOBAL(request_uri, "REQUEST_URI"); - DEF_GLOBAL(fragment, "FRAGMENT"); - DEF_GLOBAL(query_string, "QUERY_STRING"); - DEF_GLOBAL(http_version, "HTTP_VERSION"); - DEF_GLOBAL(request_path, "REQUEST_PATH"); - DEF_GLOBAL(path_info, "PATH_INFO"); - DEF_GLOBAL(server_name, "SERVER_NAME"); - DEF_GLOBAL(server_port, "SERVER_PORT"); - DEF_GLOBAL(server_protocol, "SERVER_PROTOCOL"); - DEF_GLOBAL(server_protocol_value, "HTTP/1.1"); - DEF_GLOBAL(http_x_forwarded_proto, "HTTP_X_FORWARDED_PROTO"); - DEF_GLOBAL(port_80, "80"); - DEF_GLOBAL(port_443, "443"); - DEF_GLOBAL(localhost, "localhost"); - DEF_GLOBAL(http, "http"); - - eHttpParserError = rb_define_class_under(mUnicorn, "HttpParserError", rb_eIOError); - - cHttpParser = rb_define_class_under(mUnicorn, "HttpParser", rb_cObject); + init_globals(); rb_define_alloc_func(cHttpParser, HttpParser_alloc); rb_define_method(cHttpParser, "initialize", HttpParser_init,0); rb_define_method(cHttpParser, "reset", HttpParser_reset,0); rb_define_method(cHttpParser, "execute", HttpParser_execute,2); - sym_http_body = ID2SYM(rb_intern("http_body")); init_common_fields(); g_http_host = find_common_field("HOST", 4); assert(g_http_host != Qnil); -- cgit v1.2.3-24-ge0c7