From 9a028876d23c7aab1420d81d3c001fbc91354538 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Jun 2010 02:46:08 +0000 Subject: http: move Version: header check into a less common path Since the "Version" header is uncommon and never hits our optimized case, we don't need to check for it in the common case. --- ext/unicorn_http/unicorn_http.rl | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index aa23024..f6c632f 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -173,8 +173,20 @@ static void write_value(VALUE req, struct http_parser *hp, VALIDATE_MAX_LENGTH(LEN(mark, p), FIELD_VALUE); v = LEN(mark, p) == 0 ? rb_str_buf_new(128) : STR_NEW(mark, p); if (NIL_P(f)) { - VALIDATE_MAX_LENGTH(hp->s.field_len, FIELD_NAME); - f = uncommon_field(PTR_TO(start.field), hp->s.field_len); + const char *field = PTR_TO(start.field); + size_t flen = hp->s.field_len; + + VALIDATE_MAX_LENGTH(flen, FIELD_NAME); + + /* + * ignore "Version" headers since they conflict with the HTTP_VERSION + * rack env variable. + */ + if (CONST_MEM_EQ("VERSION", field, flen)) { + hp->cont = Qnil; + return; + } + f = uncommon_field(field, flen); } else if (f == g_http_connection) { hp_keepalive_connection(hp, v); } else if (f == g_content_length) { @@ -197,15 +209,6 @@ static void write_value(VALUE req, struct http_parser *hp, assert_frozen(f); } - /* - * ignore "Version" headers since they conflict with the HTTP_VERSION - * rack env variable. - */ - if (rb_str_cmp(f, g_http_version) == 0) { - hp->cont = Qnil; - return; - } - e = rb_hash_aref(req, f); if (NIL_P(e)) { hp->cont = rb_hash_aset(req, f, v); -- cgit v1.2.3-24-ge0c7