From: Eric Wong <normalperson-rMlxZR9MS24@public.gmane.org>
To: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
Subject: [PATCH] join repeated headers with a comma
Date: Sun, 9 Aug 2009 17:10:22 -0700 [thread overview]
Message-ID: <20090810001022.GA17572@dcvr.yhbt.net> (raw)
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
next reply other threads:[~2009-08-10 0:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-10 0:10 Eric Wong [this message]
[not found] ` <20090810001022.GA17572-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
2009-08-10 0:19 ` [PATCH] join repeated headers with a comma Eric Wong
replies disabled, historical list
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).