From 14d8cca4f2f92858cc76f39403392d0e49fe587c Mon Sep 17 00:00:00 2001 From: evanweaver Date: Fri, 26 Oct 2007 09:23:10 +0000 Subject: break classes into their own files git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@766 19e92222-5c0b-0410-8929-a290d50e31e9 --- lib/mongrel/header_out.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/mongrel/header_out.rb (limited to 'lib/mongrel/header_out.rb') diff --git a/lib/mongrel/header_out.rb b/lib/mongrel/header_out.rb new file mode 100644 index 0000000..b34e95e --- /dev/null +++ b/lib/mongrel/header_out.rb @@ -0,0 +1,28 @@ +module Mongrel + # This class implements a simple way of constructing the HTTP headers dynamically + # via a Hash syntax. Think of it as a write-only Hash. Refer to HttpResponse for + # information on how this is used. + # + # One consequence of this write-only nature is that you can write multiple headers + # by just doing them twice (which is sometimes needed in HTTP), but that the normal + # semantics for Hash (where doing an insert replaces) is not there. + class HeaderOut + attr_reader :out + attr_accessor :allowed_duplicates + + def initialize(out) + @sent = {} + @allowed_duplicates = {"Set-Cookie" => true, "Set-Cookie2" => true, + "Warning" => true, "WWW-Authenticate" => true} + @out = out + end + + # Simply writes "#{key}: #{value}" to an output buffer. + def[]=(key,value) + if not @sent.has_key?(key) or @allowed_duplicates.has_key?(key) + @sent[key] = true + @out.write(Const::HEADER_FORMAT % [key, value]) + end + end + end +end \ No newline at end of file -- cgit v1.2.3-24-ge0c7