OSDN Git Service

b34e95e933092e79aedaf06d1cbf9c6e5fe37461
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / mongrel-1.1.5-x86-mswin32-60 / lib / mongrel / header_out.rb
1 module Mongrel
2   # This class implements a simple way of constructing the HTTP headers dynamically
3   # via a Hash syntax.  Think of it as a write-only Hash.  Refer to HttpResponse for
4   # information on how this is used.
5   #
6   # One consequence of this write-only nature is that you can write multiple headers
7   # by just doing them twice (which is sometimes needed in HTTP), but that the normal
8   # semantics for Hash (where doing an insert replaces) is not there.
9   class HeaderOut
10     attr_reader :out
11     attr_accessor :allowed_duplicates
12
13     def initialize(out)
14       @sent = {}
15       @allowed_duplicates = {"Set-Cookie" => true, "Set-Cookie2" => true,
16         "Warning" => true, "WWW-Authenticate" => true}
17       @out = out
18     end
19
20     # Simply writes "#{key}: #{value}" to an output buffer.
21     def[]=(key,value)
22       if not @sent.has_key?(key) or @allowed_duplicates.has_key?(key)
23         @sent[key] = true
24         @out.write(Const::HEADER_FORMAT % [key, value])
25       end
26     end
27   end
28 end