about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-02 15:22:00 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-09 01:28:23 -0700
commit4c46783d3ea2114ff8379558a0b1d1e9e933b8f1 (patch)
tree3c4e62a594bb2308ff648850af1d73b30b84ab25
parent04872aa8c6e7a88d56add4e082b485da02da33f0 (diff)
downloadunicorn-4c46783d3ea2114ff8379558a0b1d1e9e933b8f1.tar.gz
It's mostly uninteresting code.
-rw-r--r--ext/unicorn_http/unicorn_http.rl30
1 files changed, 19 insertions, 11 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 462281c..8ddf4cc 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -183,21 +183,16 @@ static int is_https(VALUE str)
   return RSTRING_LEN(str) == 5 && !memcmp("https", RSTRING_PTR(str), 5);
 }
 
-/** Finalizes the request header to have a bunch of stuff that's needed. */
-static void header_done(VALUE req, const char *at, size_t length)
+static void set_server_params(VALUE req)
 {
+  VALUE temp = rb_hash_aref(req, g_rack_url_scheme);
   VALUE server_name = g_localhost;
   VALUE server_port = g_port_80;
-  VALUE temp;
-
-  /* rack requires QUERY_STRING */
-  if (rb_hash_aref(req, g_query_string) == Qnil)
-    rb_hash_aset(req, g_query_string, rb_str_new(NULL, 0));
 
   /* set rack.url_scheme to "https" or "http", no others are allowed by Rack */
-  if ((temp = rb_hash_aref(req, g_rack_url_scheme)) == Qnil) {
-    if ((temp = rb_hash_aref(req, g_http_x_forwarded_proto)) != Qnil &&
-        is_https(temp))
+  if (temp == Qnil) {
+    temp = rb_hash_aref(req, g_http_x_forwarded_proto);
+    if (temp != Qnil && is_https(temp))
       server_port = g_port_443;
     else
       temp = g_http;
@@ -207,7 +202,8 @@ static void header_done(VALUE req, const char *at, size_t length)
   }
 
   /* parse and set the SERVER_NAME and SERVER_PORT variables */
-  if ((temp = rb_hash_aref(req, g_http_host)) != Qnil) {
+  temp = rb_hash_aref(req, g_http_host);
+  if (temp != Qnil) {
     char *colon = memchr(RSTRING_PTR(temp), ':', RSTRING_LEN(temp));
     if (colon) {
       long port_start = colon - RSTRING_PTR(temp) + 1;
@@ -221,6 +217,18 @@ static void header_done(VALUE req, const char *at, size_t length)
   }
   rb_hash_aset(req, g_server_name, server_name);
   rb_hash_aset(req, g_server_port, server_port);
+}
+
+/** Finalizes the request header to have a bunch of stuff that's needed. */
+static void header_done(VALUE req, const char *at, size_t length)
+{
+  VALUE temp;
+
+  /* rack requires QUERY_STRING */
+  if (rb_hash_aref(req, g_query_string) == Qnil)
+    rb_hash_aset(req, g_query_string, rb_str_new(NULL, 0));
+
+  set_server_params(req);
   rb_hash_aset(req, g_server_protocol, g_server_protocol_value);
 
   /* grab the initial body and stuff it into the hash */