From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.mongrel.devel Subject: [PATCH] join repeated headers with a comma Date: Sun, 9 Aug 2009 17:10:22 -0700 Message-ID: <20090810001022.GA17572@dcvr.yhbt.net> Reply-To: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1249863036 30034 80.91.229.12 (10 Aug 2009 00:10:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Aug 2009 00:10:36 +0000 (UTC) To: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Original-X-From: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Mon Aug 10 02:10:29 2009 Return-path: Envelope-to: gclrmd-mongrel-development@m.gmane.org Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-BeenThere: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.mongrel.devel:150 Archived-At: Received: from rubyforge.org ([205.234.109.19]) by lo.gmane.org with esmtp (Exim 4.50) id 1MaIT6-0007hj-Et for gclrmd-mongrel-development@m.gmane.org; Mon, 10 Aug 2009 02:10:28 +0200 Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 29D921858125; Sun, 9 Aug 2009 20:10:26 -0400 (EDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 3E8981858120 for ; Sun, 9 Aug 2009 20:10:24 -0400 (EDT) Received: from localhost (user-118bg0q.cable.mindspring.com [66.133.192.26]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id A2D241F7E0; Mon, 10 Aug 2009 00:10:23 +0000 (UTC) List-Post: These are joined in in accordance with rfc2616, section 4.2[1]. This is also ticket #50 in Trac: http://mongrel.rubyforge.org/ticket/50 [1] - http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 --- This applies against c365ba16d12a14bdf1cc50a26f67dd3b45f5a4d8 in Evan's fauna repository, I'm completely certain where I should be applying this but it should be trivial to port this patch to anything else remotely resembling it... ext/http11/http11.c | 9 ++++++++- test/unit/test_http_parser.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ext/http11/http11.c b/ext/http11/http11.c index a228019..a770c60 100644 --- a/ext/http11/http11.c +++ b/ext/http11/http11.c @@ -182,6 +182,7 @@ void http_field(void *data, const char *field, size_t flen, const char *value, s VALUE req = (VALUE)data; VALUE v = Qnil; VALUE f = Qnil; + VALUE e = Qnil; VALIDATE_MAX_LENGTH(flen, FIELD_NAME); VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE); @@ -208,7 +209,13 @@ void http_field(void *data, const char *field, size_t flen, const char *value, s /* fprintf(stderr, "UNKNOWN HEADER <%s>\n", RSTRING_PTR(f)); */ } - rb_hash_aset(req, f, v); + e = rb_hash_aref(req, f); + if (e == Qnil) { + rb_hash_aset(req, f, v); + } else { + rb_str_buf_cat(e, ",", 1); + rb_str_buf_append(e, v); + } } void request_method(void *data, const char *at, size_t length) diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index c89cd0d..70d9c91 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -173,6 +173,14 @@ class HttpParserTest < Test::Unit::TestCase assert_equal 4,res["zed"].length, "wrong number for zed" assert_equal "11",res["frank"], "wrong number for frank" end - + + def test_combine_repeat_headers + parser = HttpParser.new + http = "GET / HTTP/1.1\r\nA: 1\r\nA: 2\r\n\r\n" + req = {} + assert_nothing_raised { parser.execute(req, http, 0) } + assert_equal '1,2', req['HTTP_A'] + end + end -- Eric Wong