about summary refs log tree commit homepage
path: root/lib/mongrel/header_out.rb
diff options
context:
space:
mode:
authorevanweaver <evanweaver@19e92222-5c0b-0410-8929-a290d50e31e9>2007-10-26 09:23:10 +0000
committerevanweaver <evanweaver@19e92222-5c0b-0410-8929-a290d50e31e9>2007-10-26 09:23:10 +0000
commit14d8cca4f2f92858cc76f39403392d0e49fe587c (patch)
tree0eedc907453b7806dbc01f114f86dceba6d6d4d7 /lib/mongrel/header_out.rb
parent1b1d758124a0f30e0a331716e6684973ca2bc94b (diff)
downloadunicorn-14d8cca4f2f92858cc76f39403392d0e49fe587c.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@766 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel/header_out.rb')
-rw-r--r--lib/mongrel/header_out.rb28
1 files changed, 28 insertions, 0 deletions
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