From 04872aa8c6e7a88d56add4e082b485da02da33f0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 2 Aug 2009 15:00:03 -0700 Subject: http: minor cleanup of http_field handling Create a Ruby string object before jumping into the function to reduce the number of parameters passed and to take advantage of our STR_NEW macro to reduce noise. --- ext/unicorn_http/unicorn_http.rl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index 48fc5fc..462281c 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -24,8 +24,7 @@ struct http_parser { size_t field_len; }; -static void http_field(VALUE req, const char *field, - size_t flen, const char *value, size_t vlen); +static void http_field(VALUE req, const char *field, size_t flen, VALUE val); static void header_done(VALUE req, const char *at, size_t length); static int http_parser_has_error(struct http_parser *hp); @@ -50,8 +49,8 @@ static int http_parser_is_finished(struct http_parser *hp); action write_field { hp->field_len = LEN(start.field, fpc); } action start_value { MARK(mark, fpc); } action write_value { - http_field(req, PTR_TO(start.field), hp->field_len, - PTR_TO(mark), LEN(mark, fpc)); + VALIDATE_MAX_LENGTH(LEN(mark, fpc), FIELD_VALUE); + http_field(req, PTR_TO(start.field), hp->field_len, STR_NEW(mark, fpc)); } action request_method { rb_hash_aset(req, g_request_method, STR_NEW(mark, fpc)); @@ -165,14 +164,10 @@ static struct http_parser *data_get(VALUE self) assert(hp); return hp; } - -static void http_field(VALUE req, const char *field, - size_t flen, const char *value, size_t vlen) +static void http_field(VALUE req, const char *field, size_t flen, VALUE val) { VALUE f = find_common_field(field, flen); - VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE); - if (f == Qnil) { VALIDATE_MAX_LENGTH(flen, FIELD_NAME); f = uncommon_field(field, flen); @@ -180,7 +175,7 @@ static void http_field(VALUE req, const char *field, return; } - rb_hash_aset(req, f, rb_str_new(value, vlen)); + rb_hash_aset(req, f, val); } static int is_https(VALUE str) -- cgit v1.2.3-24-ge0c7