From 7bb9cf8e08eae1ab9fa058d62753eda044707627 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 2 Aug 2009 15:10:11 -0700 Subject: http: small cleanup in "https" detection --- ext/unicorn_http/unicorn_http.rl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 1938836..48fc5fc 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -183,6 +183,11 @@ static void http_field(VALUE req, const char *field, rb_hash_aset(req, f, rb_str_new(value, vlen)); } +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) { @@ -197,13 +202,12 @@ static void header_done(VALUE req, const char *at, size_t length) /* 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 && - RSTRING_LEN(temp) == 5 && - !memcmp("https", RSTRING_PTR(temp), 5)) + is_https(temp)) server_port = g_port_443; else temp = g_http; rb_hash_aset(req, g_rack_url_scheme, temp); - } else if (RSTRING_LEN(temp) == 5 && !memcmp("https", RSTRING_PTR(temp), 5)) { + } else if (is_https(temp)) { server_port = g_port_443; } -- cgit v1.2.3-24-ge0c7